-- 067_us_state_compliance_configs.sql
--
-- Annual report fees, due dates, and franchise tax info for all 51 US
-- jurisdictions.  Read by the renewal_worker to create compliance
-- calendar entries for formation clients.

BEGIN;

CREATE TABLE IF NOT EXISTS state_compliance_obligations (
    id                  SERIAL PRIMARY KEY,
    state_code          CHAR(2) NOT NULL,
    obligation_type     TEXT NOT NULL CHECK (obligation_type IN (
        'annual_report', 'franchise_tax', 'biennial_report',
        'business_license', 'registered_agent'
    )),
    fee_cents           INTEGER NOT NULL DEFAULT 0,
    fee_notes           TEXT,                           -- "min $50, max $15,000" etc.
    frequency           TEXT NOT NULL DEFAULT 'annual'
                        CHECK (frequency IN ('annual', 'biennial', 'quarterly', 'none')),
    due_description     TEXT,                           -- "April 15" or "anniversary month"
    due_month           INTEGER,                        -- 1-12 if fixed month; NULL if anniversary
    due_day             INTEGER,                        -- 1-31 if fixed day
    is_anniversary      BOOLEAN NOT NULL DEFAULT FALSE, -- due relative to formation date
    state_portal_url    TEXT,
    notes               TEXT,
    created_at          TIMESTAMPTZ NOT NULL DEFAULT NOW(),

    UNIQUE (state_code, obligation_type)
);

-- Seed annual report obligations for all 51 US jurisdictions.
-- Source: docs/annual-report-fees-by-state.md (LLC University + state SOS cross-ref)
INSERT INTO state_compliance_obligations
    (state_code, obligation_type, fee_cents, fee_notes, frequency, due_description, due_month, due_day, is_anniversary, notes)
VALUES
    ('AL', 'annual_report',    5000,  'Min $50, scales with net worth up to $15,000', 'annual', 'April 15', 4, 15, FALSE, 'Called "Business Privilege Tax"'),
    ('AK', 'biennial_report',  10000, '$100 biennial', 'biennial', 'January 2 of even years', 1, 2, FALSE, NULL),
    ('AZ', 'annual_report',    0,     NULL, 'none', NULL, NULL, NULL, FALSE, 'No annual report required for LLCs'),
    ('AR', 'franchise_tax',    15000, NULL, 'annual', 'May 1', 5, 1, FALSE, 'Called "Franchise Tax Report"'),
    ('CA', 'franchise_tax',    80000, '$800 franchise tax minimum', 'annual', 'April 15', 4, 15, FALSE, 'Additional fee if gross revenue > $250k'),
    ('CA', 'biennial_report',  2000,  '$20 biennial Statement of Information', 'biennial', 'Anniversary month', NULL, NULL, TRUE, NULL),
    ('CO', 'annual_report',    2500,  NULL, 'annual', 'Anniversary month', NULL, NULL, TRUE, 'Due within 5-month window around anniversary'),
    ('CT', 'annual_report',    8000,  NULL, 'annual', 'March 31', 3, 31, FALSE, NULL),
    ('DC', 'biennial_report',  30000, '$300 biennial', 'biennial', 'April 1', 4, 1, FALSE, NULL),
    ('DE', 'franchise_tax',    30000, NULL, 'annual', 'June 1', 6, 1, FALSE, '$300/yr LLC franchise tax'),
    ('FL', 'annual_report',    13875, NULL, 'annual', 'May 1', 5, 1, FALSE, NULL),
    ('GA', 'annual_report',    6000,  NULL, 'annual', 'April 1', 4, 1, FALSE, 'Called "Annual Registration"'),
    ('HI', 'annual_report',    1500,  NULL, 'annual', 'Anniversary quarter', NULL, NULL, TRUE, NULL),
    ('ID', 'annual_report',    0,     NULL, 'annual', 'Anniversary month', NULL, NULL, TRUE, 'Must file information report but no fee'),
    ('IL', 'annual_report',    7500,  NULL, 'annual', 'Anniversary month', NULL, NULL, TRUE, NULL),
    ('IN', 'biennial_report',  3000,  '$30 biennial', 'biennial', 'Anniversary month', NULL, NULL, TRUE, NULL),
    ('IA', 'biennial_report',  3000,  '$30 biennial', 'biennial', 'April 1 of odd years', 4, 1, FALSE, NULL),
    ('KS', 'annual_report',    5000,  NULL, 'annual', 'April 15', 4, 15, FALSE, NULL),
    ('KY', 'annual_report',    1500,  NULL, 'annual', 'June 30', 6, 30, FALSE, NULL),
    ('LA', 'annual_report',    3500,  NULL, 'annual', 'Anniversary month', NULL, NULL, TRUE, NULL),
    ('ME', 'annual_report',    8500,  NULL, 'annual', 'June 1', 6, 1, FALSE, NULL),
    ('MD', 'annual_report',    30000, NULL, 'annual', 'April 15', 4, 15, FALSE, 'Personal property tax return functions as annual report'),
    ('MA', 'annual_report',    50000, NULL, 'annual', 'Anniversary month', NULL, NULL, TRUE, NULL),
    ('MI', 'annual_report',    2500,  NULL, 'annual', 'February 15', 2, 15, FALSE, NULL),
    ('MN', 'annual_report',    0,     NULL, 'annual', 'December 31', 12, 31, FALSE, 'Must file but no fee'),
    ('MS', 'annual_report',    0,     NULL, 'annual', 'April 15', 4, 15, FALSE, 'Must file but no fee'),
    ('MO', 'annual_report',    0,     NULL, 'none', NULL, NULL, NULL, FALSE, 'No annual report required'),
    ('MT', 'annual_report',    2000,  NULL, 'annual', 'April 15', 4, 15, FALSE, NULL),
    ('NE', 'biennial_report',  1300,  '$13 biennial', 'biennial', 'April 1 of odd years', 4, 1, FALSE, NULL),
    ('NV', 'annual_report',    15000, '$150 Annual List of Members', 'annual', 'Anniversary month', NULL, NULL, TRUE, NULL),
    ('NV', 'business_license', 20000, '$200 State Business License', 'annual', 'Anniversary month', NULL, NULL, TRUE, 'Separate from Annual List'),
    ('NH', 'annual_report',    10000, NULL, 'annual', 'April 1', 4, 1, FALSE, NULL),
    ('NJ', 'annual_report',    7500,  NULL, 'annual', 'Anniversary month', NULL, NULL, TRUE, NULL),
    ('NM', 'annual_report',    0,     NULL, 'none', NULL, NULL, NULL, FALSE, 'No annual report required'),
    ('NY', 'biennial_report',  900,   '$9 biennial', 'biennial', 'Anniversary month', NULL, NULL, TRUE, NULL),
    ('NC', 'annual_report',    20000, NULL, 'annual', 'April 15', 4, 15, FALSE, NULL),
    ('ND', 'annual_report',    5000,  NULL, 'annual', 'November 15', 11, 15, FALSE, NULL),
    ('OH', 'annual_report',    0,     NULL, 'none', NULL, NULL, NULL, FALSE, 'No annual report required'),
    ('OK', 'annual_report',    2500,  NULL, 'annual', 'Anniversary month', NULL, NULL, TRUE, 'Called "Annual Certificate"'),
    ('OR', 'annual_report',    10000, NULL, 'annual', 'Anniversary month', NULL, NULL, TRUE, NULL),
    ('PA', 'annual_report',    700,   NULL, 'annual', 'September 30', 9, 30, FALSE, 'New requirement starting 2025'),
    ('RI', 'annual_report',    5000,  NULL, 'annual', 'Between February 1 and May 1', 5, 1, FALSE, NULL),
    ('SC', 'annual_report',    0,     NULL, 'none', NULL, NULL, NULL, FALSE, 'No annual report for standard LLCs'),
    ('SD', 'annual_report',    5500,  NULL, 'annual', 'Anniversary month', NULL, NULL, TRUE, NULL),
    ('TN', 'annual_report',    30000, 'Min $300 ($300/member, max $3,000)', 'annual', 'Anniversary month', NULL, NULL, TRUE, NULL),
    ('TX', 'franchise_tax',    0,     '$0 for most LLCs (< $2.47M revenue)', 'annual', 'May 15', 5, 15, FALSE, 'Must file Public Information Report regardless'),
    ('UT', 'annual_report',    1800,  NULL, 'annual', 'Anniversary month', NULL, NULL, TRUE, 'Called "Annual Renewal"'),
    ('VT', 'annual_report',    4500,  NULL, 'annual', 'March 15', 3, 15, FALSE, NULL),
    ('VA', 'annual_report',    5000,  NULL, 'annual', 'Anniversary month', NULL, NULL, TRUE, 'Called "Annual Registration Fee"'),
    ('WA', 'annual_report',    6000,  NULL, 'annual', 'Anniversary month', NULL, NULL, TRUE, NULL),
    ('WV', 'annual_report',    2500,  NULL, 'annual', 'July 1', 7, 1, FALSE, NULL),
    ('WI', 'annual_report',    2500,  NULL, 'annual', 'Anniversary quarter', NULL, NULL, TRUE, NULL),
    ('WY', 'annual_report',    6000,  'Min $60, scales with WY assets', 'annual', 'Anniversary month', NULL, NULL, TRUE, NULL)
ON CONFLICT (state_code, obligation_type) DO UPDATE SET
    fee_cents = EXCLUDED.fee_cents,
    fee_notes = EXCLUDED.fee_notes,
    frequency = EXCLUDED.frequency,
    due_description = EXCLUDED.due_description,
    due_month = EXCLUDED.due_month,
    due_day = EXCLUDED.due_day,
    is_anniversary = EXCLUDED.is_anniversary,
    notes = EXCLUDED.notes;

COMMIT;
