-- SAT Chart of Accounts (Catalogo de Cuentas SAT)
-- All accounts are system accounts (is_system = true)
-- Individual INSERTs so parent_id subqueries can resolve correctly.

-- ============================================================
-- ACTIVO (100)
-- ============================================================
INSERT INTO accounts (code, name, parent_id, type, sat_code, is_system, is_active)
VALUES ('100', 'Activo', NULL, 'activo', '100', true, true);
INSERT INTO accounts (code, name, parent_id, type, sat_code, is_system, is_active)
VALUES ('110', 'Caja', (SELECT id FROM accounts WHERE code = '100'), 'activo', '110', true, true);
INSERT INTO accounts (code, name, parent_id, type, sat_code, is_system, is_active)
VALUES ('111', 'Bancos', (SELECT id FROM accounts WHERE code = '100'), 'activo', '111', true, true);
INSERT INTO accounts (code, name, parent_id, type, sat_code, is_system, is_active)
VALUES ('120', 'Clientes', (SELECT id FROM accounts WHERE code = '100'), 'activo', '120', true, true);
INSERT INTO accounts (code, name, parent_id, type, sat_code, is_system, is_active)
VALUES ('130', 'Inventarios', (SELECT id FROM accounts WHERE code = '100'), 'activo', '130', true, true);
INSERT INTO accounts (code, name, parent_id, type, sat_code, is_system, is_active)
VALUES ('140', 'IVA Acreditable', (SELECT id FROM accounts WHERE code = '100'), 'activo', '140', true, true);

-- ============================================================
-- PASIVO (200)
-- ============================================================
INSERT INTO accounts (code, name, parent_id, type, sat_code, is_system, is_active)
VALUES ('200', 'Pasivo', NULL, 'pasivo', '200', true, true);
INSERT INTO accounts (code, name, parent_id, type, sat_code, is_system, is_active)
VALUES ('210', 'Proveedores', (SELECT id FROM accounts WHERE code = '200'), 'pasivo', '210', true, true);
INSERT INTO accounts (code, name, parent_id, type, sat_code, is_system, is_active)
VALUES ('220', 'IVA Trasladado', (SELECT id FROM accounts WHERE code = '200'), 'pasivo', '220', true, true);
INSERT INTO accounts (code, name, parent_id, type, sat_code, is_system, is_active)
VALUES ('230', 'ISR por Pagar', (SELECT id FROM accounts WHERE code = '200'), 'pasivo', '230', true, true);

-- ============================================================
-- CAPITAL (300)
-- ============================================================
INSERT INTO accounts (code, name, parent_id, type, sat_code, is_system, is_active)
VALUES ('300', 'Capital', NULL, 'capital', '300', true, true);
INSERT INTO accounts (code, name, parent_id, type, sat_code, is_system, is_active)
VALUES ('310', 'Capital Social', (SELECT id FROM accounts WHERE code = '300'), 'capital', '310', true, true);
INSERT INTO accounts (code, name, parent_id, type, sat_code, is_system, is_active)
VALUES ('320', 'Resultados del Ejercicio', (SELECT id FROM accounts WHERE code = '300'), 'capital', '320', true, true);

-- ============================================================
-- INGRESOS (400)
-- ============================================================
INSERT INTO accounts (code, name, parent_id, type, sat_code, is_system, is_active)
VALUES ('400', 'Ingresos', NULL, 'ingreso', '400', true, true);
INSERT INTO accounts (code, name, parent_id, type, sat_code, is_system, is_active)
VALUES ('410', 'Ventas', (SELECT id FROM accounts WHERE code = '400'), 'ingreso', '410', true, true);
INSERT INTO accounts (code, name, parent_id, type, sat_code, is_system, is_active)
VALUES ('420', 'Devoluciones sobre Ventas', (SELECT id FROM accounts WHERE code = '400'), 'ingreso', '420', true, true);

-- ============================================================
-- COSTOS (500)
-- ============================================================
INSERT INTO accounts (code, name, parent_id, type, sat_code, is_system, is_active)
VALUES ('500', 'Costos', NULL, 'costo', '500', true, true);
INSERT INTO accounts (code, name, parent_id, type, sat_code, is_system, is_active)
VALUES ('510', 'Costo de Mercancia Vendida', (SELECT id FROM accounts WHERE code = '500'), 'costo', '510', true, true);

-- ============================================================
-- GASTOS (600)
-- ============================================================
INSERT INTO accounts (code, name, parent_id, type, sat_code, is_system, is_active)
VALUES ('600', 'Gastos', NULL, 'gasto', '600', true, true);
INSERT INTO accounts (code, name, parent_id, type, sat_code, is_system, is_active)
VALUES ('610', 'Gastos Operativos', (SELECT id FROM accounts WHERE code = '600'), 'gasto', '610', true, true);
INSERT INTO accounts (code, name, parent_id, type, sat_code, is_system, is_active)
VALUES ('620', 'Gastos Financieros', (SELECT id FROM accounts WHERE code = '600'), 'gasto', '620', true, true);
