-- Seed plan de cuentas básico para empresa demo (genérico / inspirado en PUC simplificado)
-- Ejecutar tras db_schema_accounting.sql y db_seed_organization.sql

-- Empresa demo
-- id: d1e2f3a4-b5c6-4d7e-8f9a-0b1c2d3e4f5a

INSERT INTO chart_accounts (id, company_id, parent_id, code, name, account_type, is_header, is_active)
VALUES
  ('a1000001-0000-4000-8000-000000000001', 'd1e2f3a4-b5c6-4d7e-8f9a-0b1c2d3e4f5a', NULL, '1', 'Activo', 'asset', TRUE, TRUE),
  ('a1000001-0000-4000-8000-000000000011', 'd1e2f3a4-b5c6-4d7e-8f9a-0b1c2d3e4f5a', 'a1000001-0000-4000-8000-000000000001', '11', 'Disponible', 'asset', TRUE, TRUE),
  ('a1000001-0000-4000-8000-000000000111', 'd1e2f3a4-b5c6-4d7e-8f9a-0b1c2d3e4f5a', 'a1000001-0000-4000-8000-000000000011', '1105', 'Caja', 'asset', FALSE, TRUE),
  ('a1000001-0000-4000-8000-000000000112', 'd1e2f3a4-b5c6-4d7e-8f9a-0b1c2d3e4f5a', 'a1000001-0000-4000-8000-000000000011', '1110', 'Bancos', 'asset', FALSE, TRUE),
  ('a1000001-0000-4000-8000-000000000002', 'd1e2f3a4-b5c6-4d7e-8f9a-0b1c2d3e4f5a', NULL, '2', 'Pasivo', 'liability', TRUE, TRUE),
  ('a1000001-0000-4000-8000-000000000021', 'd1e2f3a4-b5c6-4d7e-8f9a-0b1c2d3e4f5a', 'a1000001-0000-4000-8000-000000000002', '21', 'Obligaciones financieras', 'liability', TRUE, TRUE),
  ('a1000001-0000-4000-8000-000000000211', 'd1e2f3a4-b5c6-4d7e-8f9a-0b1c2d3e4f5a', 'a1000001-0000-4000-8000-000000000021', '2105', 'Proveedores', 'liability', FALSE, TRUE),
  ('a1000001-0000-4000-8000-000000000003', 'd1e2f3a4-b5c6-4d7e-8f9a-0b1c2d3e4f5a', NULL, '3', 'Patrimonio', 'equity', TRUE, TRUE),
  ('a1000001-0000-4000-8000-000000000031', 'd1e2f3a4-b5c6-4d7e-8f9a-0b1c2d3e4f5a', 'a1000001-0000-4000-8000-000000000003', '31', 'Capital social', 'equity', TRUE, TRUE),
  ('a1000001-0000-4000-8000-000000000311', 'd1e2f3a4-b5c6-4d7e-8f9a-0b1c2d3e4f5a', 'a1000001-0000-4000-8000-000000000031', '3105', 'Capital suscrito', 'equity', FALSE, TRUE),
  ('a1000001-0000-4000-8000-000000000004', 'd1e2f3a4-b5c6-4d7e-8f9a-0b1c2d3e4f5a', NULL, '4', 'Ingresos', 'income', TRUE, TRUE),
  ('a1000001-0000-4000-8000-000000000041', 'd1e2f3a4-b5c6-4d7e-8f9a-0b1c2d3e4f5a', 'a1000001-0000-4000-8000-000000000004', '41', 'Operacionales', 'income', TRUE, TRUE),
  ('a1000001-0000-4000-8000-000000000411', 'd1e2f3a4-b5c6-4d7e-8f9a-0b1c2d3e4f5a', 'a1000001-0000-4000-8000-000000000041', '4135', 'Ventas', 'income', FALSE, TRUE),
  ('a1000001-0000-4000-8000-000000000005', 'd1e2f3a4-b5c6-4d7e-8f9a-0b1c2d3e4f5a', NULL, '5', 'Gastos', 'expense', TRUE, TRUE),
  ('a1000001-0000-4000-8000-000000000051', 'd1e2f3a4-b5c6-4d7e-8f9a-0b1c2d3e4f5a', 'a1000001-0000-4000-8000-000000000005', '51', 'Operacionales de administración', 'expense', TRUE, TRUE),
  ('a1000001-0000-4000-8000-000000000511', 'd1e2f3a4-b5c6-4d7e-8f9a-0b1c2d3e4f5a', 'a1000001-0000-4000-8000-000000000051', '5105', 'Gastos de personal', 'expense', FALSE, TRUE)
ON CONFLICT (company_id, code) DO UPDATE
SET name = EXCLUDED.name,
    parent_id = EXCLUDED.parent_id,
    account_type = EXCLUDED.account_type,
    is_header = EXCLUDED.is_header,
    is_active = EXCLUDED.is_active,
    updated_at = CURRENT_TIMESTAMP;

-- Tipo de cambio ejemplo COP → USD (empresa funcional USD)
INSERT INTO exchange_rates (company_id, rate_date, from_currency, to_currency, rate)
VALUES (
  'd1e2f3a4-b5c6-4d7e-8f9a-0b1c2d3e4f5a',
  CURRENT_DATE,
  'COP',
  'USD',
  0.00025
)
ON CONFLICT (company_id, rate_date, from_currency, to_currency) DO UPDATE
SET rate = EXCLUDED.rate;
