-- ============================================================
-- quoERP — Datos iniciales (seed)
-- Ejecutar DESPUÉS de 001_create_all_tables.sql
-- ============================================================


-- ── Empresa demo ──────────────────────────────────────────
INSERT INTO companies (name, code, ruc, legal_name, color, chat_retention_days) VALUES
('MENRICORP Demo', 'MNC', '0190123456001', 'MENRICORP Soluciones Tecnológicas', '#1B3A6B', 90);

-- ── Oficinas ──────────────────────────────────────────────
INSERT INTO offices (company_id, name, city, is_main) VALUES
(1, 'Oficina Central — Cuenca',  'Cuenca',   1),
(1, 'Sucursal Quito Norte',      'Quito',    0),
(1, 'Sucursal Guayaquil',        'Guayaquil',0);

-- ── Roles del sistema ─────────────────────────────────────
INSERT INTO roles (company_id, slug, label, level, is_system, permissions, description) VALUES
(NULL, 'superadmin', 'Super Administrador', 100, 1,
 '{"*":["*"]}',
 'Acceso total al sistema. Gestiona todas las empresas, oficinas y usuarios.'),

(NULL, 'admin', 'Administrador', 80, 1,
 '{"dashboard":["view"],"sales":["*"],"inventory":["*"],"purchases":["*"],"finance":["*"],"hr":["*"],"payroll":["*"],"chat":["*"],"admin_users":["*"],"settings":["*"]}',
 'Administra una empresa. Gestiona usuarios y configuración.'),

(NULL, 'manager', 'Gerente', 60, 1,
 '{"dashboard":["view"],"sales":["view","create","edit"],"inventory":["view","create","edit"],"purchases":["view","create","edit"],"finance":["view"],"hr":["view"],"payroll":["view"],"chat":["*"]}',
 'Acceso gerencial a módulos operativos y financieros.'),

(NULL, 'supervisor', 'Supervisor', 40, 1,
 '{"dashboard":["view"],"sales":["view","create","edit"],"inventory":["view","create"],"chat":["*"]}',
 'Gestión operativa de módulos asignados. Aprobación de transacciones.'),

(NULL, 'user', 'Usuario', 20, 1,
 '{"dashboard":["view"],"chat":["*"]}',
 'Operación básica en módulos asignados.');

-- ── Usuario Super Administrador inicial ───────────────────
-- Password: Admin2026! (bcrypt hash - cambiar al primer login)
-- Para generar otro hash: php -r "echo password_hash('TuPassword', PASSWORD_BCRYPT, ['cost'=>10]);"
INSERT INTO users (company_id, office_id, role_id, first_name, last_name, email, phone, password_hash, status, email_verified_at) VALUES
(1, 1, 1, 'Admin', 'quoERP', 'admin@menricorp.com', '+593 99 025 4434',
 '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi',
 'active', NOW());
-- NOTA: El hash de arriba es para 'password' (ejemplo Laravel).
-- Generar hash real con: password_hash('Admin2026!', PASSWORD_BCRYPT, ['cost' => 10])

-- ── Configuración inicial de empresa ─────────────────────
INSERT INTO company_settings (company_id, key_name, value) VALUES
(1, 'chat_retention_days', '90'),
(1, 'chat_view_mode', 'comfortable'),
(1, 'invoice_sequence', '1'),
(1, 'po_sequence', '1'),
(1, 'so_sequence', '1'),
(1, 'currency', 'USD'),
(1, 'currency_symbol', '$'),
(1, 'date_format', 'd/m/Y'),
(1, 'fiscal_year_start', '01-01');

-- ── Usuarios demo ─────────────────────────────────────────
INSERT INTO users (company_id, office_id, role_id, first_name, last_name, email, phone, password_hash, status, email_verified_at) VALUES
(1, 1, 3, 'Carlos',  'Méndez',   'c.mendez@menricorp.com',   '+593 98 111 2233', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'active', NOW()),
(1, 2, 4, 'Valeria', 'Torres',   'v.torres@menricorp.com',   '+593 97 222 3344', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'active', NOW()),
(1, 3, 5, 'Diego',   'Salcedo',  'd.salcedo@menricorp.com',  '+593 96 333 4455', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'active', NOW()),
(1, 1, 2, 'Paola',   'Romero',   'p.romero@menricorp.com',   '+593 99 444 5566', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'active', NOW());
