-- Seed the three companies

DO $$
DECLARE
    v_tenant_id UUID;
BEGIN
    -- Get or create main tenant
    INSERT INTO boc_tenants (name, slug, domain, settings)
    VALUES ('LandveX Group', 'landvex-group', 'landvex.com', '{"group": true}')
    ON CONFLICT (slug) DO UPDATE SET name = 'LandveX Group'
    RETURNING id INTO v_tenant_id;

    -- LandveX AB (Sweden)
    INSERT INTO boc_companies (
        tenant_id, name, legal_name, org_number, jurisdiction, 
        company_type, currency, fiscal_year_end, accounting_std, 
        vat_registered, vat_number, settings
    ) VALUES (
        v_tenant_id, 'LandveX AB', 'LandveX Aktiebolag', '559141-7042', 'SE',
        'Aktiebolag', 'SEK', '2026-12-31', 'BAS',
        true, 'SE559141704201', '{"moms_period": "monthly", "arbetsgivaravgift": true}'
    )
    ON CONFLICT DO NOTHING;

    -- quiXzoom Inc (Delaware)
    INSERT INTO boc_companies (
        tenant_id, name, legal_name, tax_id, jurisdiction,
        company_type, currency, fiscal_year_end, accounting_std,
        vat_registered, settings
    ) VALUES (
        v_tenant_id, 'quiXzoom Inc', 'quiXzoom Incorporated', null, 'US-DE',
        'C-Corp', 'USD', '2026-12-31', 'GAAP',
        false, '{"delaware_franchise_tax": true, "state": "DE"}'
    )
    ON CONFLICT DO NOTHING;

    -- Landvex Inc (Texas)
    INSERT INTO boc_companies (
        tenant_id, name, legal_name, tax_id, jurisdiction,
        company_type, currency, fiscal_year_end, accounting_std,
        vat_registered, settings
    ) VALUES (
        v_tenant_id, 'Landvex Inc', 'Landvex Incorporated', null, 'US-TX',
        'C-Corp', 'USD', '2026-12-31', 'GAAP',
        false, '{"texas_franchise_tax": true, "state": "TX"}'
    )
    ON CONFLICT DO NOTHING;

    RAISE NOTICE 'Three companies seeded successfully';
END $$;
