-- ============================================================================
-- ERP GENERIC - SEED DATA: COMPANIES (Development)
-- ============================================================================
-- Description: Initial companies for development environment
-- ============================================================================

-- Default company for Demo tenant
INSERT INTO auth.companies (id, tenant_id, name, legal_name, tax_id, currency_id, settings, created_at)
VALUES (
    '50fa9b29-504f-4c45-8f8a-3d129cfc6095',
    '1c7dfbb0-19b8-4e87-a225-a74da6f26dbf',
    'Demo Company S.A. de C.V.',
    'Demo Company Sociedad Anónima de Capital Variable',
    'DCO123456ABC',
    (SELECT id FROM core.currencies WHERE code = 'MXN' LIMIT 1),
    jsonb_build_object(
        'fiscal_position', 'general',
        'tax_regime', '601',
        'email', 'contacto@demo-company.mx',
        'phone', '+52 55 1234 5678',
        'website', 'https://demo-company.mx'
    ),
    CURRENT_TIMESTAMP
) ON CONFLICT (id) DO NOTHING;

-- Second company (subsidiary) for Demo tenant
INSERT INTO auth.companies (id, tenant_id, parent_company_id, name, legal_name, tax_id, currency_id, settings, created_at)
VALUES (
    'e347be2e-483e-4ab5-8d73-5ed454e304c6',
    '1c7dfbb0-19b8-4e87-a225-a74da6f26dbf',
    '50fa9b29-504f-4c45-8f8a-3d129cfc6095',
    'Demo Subsidiary',
    'Demo Subsidiary S. de R.L.',
    'DSU789012DEF',
    (SELECT id FROM core.currencies WHERE code = 'MXN' LIMIT 1),
    jsonb_build_object(
        'email', 'subsidiary@demo-company.mx',
        'phone', '+52 55 8765 4321'
    ),
    CURRENT_TIMESTAMP
) ON CONFLICT (id) DO NOTHING;

-- Company for Test Corp tenant
INSERT INTO auth.companies (id, tenant_id, name, legal_name, tax_id, currency_id, settings, created_at)
VALUES (
    '2f24ea46-7828-4125-add2-3f12644d796f',
    '204c4748-09b2-4a98-bb5a-183ec263f205',
    'Test Corporation Inc.',
    'Test Corporation Incorporated',
    '12-3456789',
    (SELECT id FROM core.currencies WHERE code = 'USD' LIMIT 1),
    jsonb_build_object(
        'email', 'info@test-corp.com',
        'phone', '+1 555 123 4567',
        'website', 'https://test-corp.com'
    ),
    CURRENT_TIMESTAMP
) ON CONFLICT (id) DO NOTHING;

-- Output confirmation
DO $$
BEGIN
    RAISE NOTICE 'Companies seed data loaded: 3 companies created';
END $$;
