-- 002_state_filing_fees.sql
-- State-by-state business formation filing fees for all 50 states + DC.
-- All monetary values in cents (e.g., 10000 = $100.00).
-- Sources: LLC University (2026), individual state SOS offices, Nolo (2025).
-- Last verified: 2026-03-19

BEGIN;

CREATE TABLE IF NOT EXISTS state_filing_fees (
    id                          SERIAL PRIMARY KEY,
    state_code                  CHAR(2) NOT NULL UNIQUE,
    state_name                  TEXT NOT NULL,
    -- LLC Formation
    llc_formation_fee           INTEGER NOT NULL,
    llc_annual_fee              INTEGER,
    llc_annual_period           TEXT,
    -- Corporation Formation
    corp_formation_fee          INTEGER NOT NULL,
    corp_annual_fee             INTEGER,
    corp_annual_period          TEXT,
    -- Foreign Qualification
    foreign_llc_fee             INTEGER,
    foreign_corp_fee            INTEGER,
    -- Expedited Processing
    expedited_fee               INTEGER,
    expedited_label             TEXT,
    -- Name Reservation
    name_reservation_fee        INTEGER,
    name_reservation_days       INTEGER,
    -- Special Requirements
    publication_required        BOOLEAN DEFAULT FALSE,
    publication_est_cost        INTEGER,
    franchise_tax_required      BOOLEAN DEFAULT FALSE,
    franchise_tax_min           INTEGER,
    franchise_tax_notes         TEXT,
    business_license_required   BOOLEAN DEFAULT FALSE,
    business_license_fee        INTEGER,
    -- Filing Portal
    portal_name                 TEXT,
    portal_url                  TEXT,
    online_filing_available     BOOLEAN DEFAULT TRUE,
    typical_processing_days     INTEGER,
    -- Metadata
    notes                       TEXT,
    fee_source_url              TEXT,
    last_verified               DATE DEFAULT '2026-03-19',
    created_at                  TIMESTAMPTZ DEFAULT now(),
    updated_at                  TIMESTAMPTZ DEFAULT now()
);

-- Also create table for NW RA wholesale pricing (to be populated later)
CREATE TABLE IF NOT EXISTS nwra_wholesale_pricing (
    id              SERIAL PRIMARY KEY,
    state_code      CHAR(2) NOT NULL,
    service_type    TEXT NOT NULL,
    wholesale_cost  INTEGER NOT NULL,
    retail_price    INTEGER NOT NULL,
    notes           TEXT,
    last_verified   DATE,
    UNIQUE(state_code, service_type)
);

-- Also create table for formation orders
CREATE TABLE IF NOT EXISTS formation_orders (
    id                      SERIAL PRIMARY KEY,
    order_number            TEXT UNIQUE NOT NULL,
    customer_name           TEXT NOT NULL,
    customer_email          TEXT NOT NULL,
    customer_phone          TEXT,
    customer_company        TEXT,
    state_code              CHAR(2) NOT NULL,
    entity_type             TEXT NOT NULL CHECK (entity_type IN ('llc', 'corporation', 's_corp')),
    entity_name             TEXT NOT NULL,
    entity_name_alt         TEXT,
    management_type         TEXT,
    registered_agent_state  CHAR(2),
    principal_address       TEXT,
    mailing_address         TEXT,
    members_json            JSONB,
    include_ra_service      BOOLEAN DEFAULT TRUE,
    include_ein             BOOLEAN DEFAULT FALSE,
    include_operating_agreement BOOLEAN DEFAULT FALSE,
    expedited               BOOLEAN DEFAULT FALSE,
    state_fee_cents         INTEGER NOT NULL,
    service_fee_cents       INTEGER NOT NULL,
    nwra_cost_cents         INTEGER NOT NULL DEFAULT 0,
    expedited_fee_cents     INTEGER DEFAULT 0,
    total_cents             INTEGER NOT NULL,
    status                  TEXT DEFAULT 'received' CHECK (status IN (
                                'received', 'processing', 'submitted', 'filed', 'delivered', 'cancelled'
                            )),
    nwra_order_id           TEXT,
    state_filing_number     TEXT,
    filed_at                TIMESTAMPTZ,
    formation_docs_url      TEXT,
    delivered_at            TIMESTAMPTZ,
    created_at              TIMESTAMPTZ DEFAULT now(),
    updated_at              TIMESTAMPTZ DEFAULT now()
);

CREATE INDEX IF NOT EXISTS idx_formation_orders_status ON formation_orders(status);
CREATE INDEX IF NOT EXISTS idx_formation_orders_state ON formation_orders(state_code);
CREATE INDEX IF NOT EXISTS idx_formation_orders_email ON formation_orders(customer_email);

-- Seed all 50 states + DC
INSERT INTO state_filing_fees (
    state_code, state_name,
    llc_formation_fee, llc_annual_fee, llc_annual_period,
    corp_formation_fee, corp_annual_fee, corp_annual_period,
    foreign_llc_fee, foreign_corp_fee,
    expedited_fee, expedited_label,
    name_reservation_fee, name_reservation_days,
    publication_required, publication_est_cost,
    franchise_tax_required, franchise_tax_min, franchise_tax_notes,
    business_license_required, business_license_fee,
    portal_name, portal_url, online_filing_available, typical_processing_days,
    notes, fee_source_url
) VALUES
('AL', 'Alabama', 20000, NULL, NULL, 20000, NULL, NULL, 20000, 20000, NULL, NULL, 280000, 120, FALSE, NULL, FALSE, NULL, 'BPT $50 min/yr', FALSE, NULL, 'AL SOS', 'sos.alabama.gov', TRUE, 7, '$50 BPT due 2.5 months after formation', 'sos.alabama.gov/sites/default/files/form-files/FeeSchedule.pdf'),
('AK', 'Alaska', 25000, 1000000, 'biennial', 25000, 1000000, 'biennial', 25000, 25000, NULL, NULL, 250000, 120, FALSE, NULL, FALSE, NULL, NULL, TRUE, 500000, 'AK CBPL', 'commerce.alaska.gov', TRUE, 10, '$50/yr state business license', 'commerce.alaska.gov/web/cbpl/Corporations'),
('AZ', 'Arizona', 5000, NULL, NULL, 6000, NULL, NULL, 15000, 18500, 1000000, 'same-day', 100000, 120, TRUE, 3000000, FALSE, NULL, NULL, FALSE, NULL, 'eCorp', 'ecorp.azcc.gov', TRUE, 5, 'Publication req ~$200-400', 'azcc.gov/corporations'),
('AR', 'Arkansas', 4500, 1500000, 'annual', 4500, 1500000, 'annual', 27500, 27500, 500000, 'same-day', 250000, 120, FALSE, NULL, FALSE, NULL, NULL, FALSE, NULL, 'AR SOS', 'sos.arkansas.gov', TRUE, 5, NULL, 'sos.arkansas.gov'),
('CA', 'California', 7000, 8000000, 'annual', 10000, 250000, 'annual', 7000, 10000, 7500000, 'same-day', 100000, 60, FALSE, NULL, TRUE, 8000000, '$800/yr franchise tax (waived 1st yr sometimes); $900-$11790 if revenue >$250K', FALSE, NULL, 'bizfile Online', 'bizfileonline.sos.ca.gov', TRUE, 5, 'Very expensive ongoing costs', 'sos.ca.gov/business-programs'),
('CO', 'Colorado', 5000, 250000, 'annual', 5000, 250000, 'annual', 10000, 10000, NULL, NULL, 250000, 120, FALSE, NULL, FALSE, NULL, NULL, FALSE, NULL, 'CO SOS', 'sos.state.co.us', TRUE, 1, 'Online filing is immediate', 'sos.state.co.us/pubs/business'),
('CT', 'Connecticut', 12000, 800000, 'annual', 25000, 1500000, 'annual', 12000, 25000, 1000000, 'same-day', 600000, 120, FALSE, NULL, FALSE, NULL, NULL, FALSE, NULL, 'CT SOTS', 'portal.ct.gov/sots', TRUE, 5, NULL, 'portal.ct.gov/sots'),
('DE', 'Delaware', 11000, 3000000, 'annual', 8900, 1750000, 'annual', 20000, 24500, 5000000, '24-hour', 750000, 120, FALSE, NULL, TRUE, 1750000, '$300/yr LLC franchise tax; Corp $175 min', FALSE, NULL, 'eCorp/ICIS', 'corp.delaware.gov', TRUE, 14, '$5000 for 1-hour rush', 'corp.delaware.gov/fee/'),
('FL', 'Florida', 12500, 1387500, 'annual', 7000, 1500000, 'annual', 12500, 7000, NULL, NULL, 250000, 120, FALSE, NULL, FALSE, NULL, NULL, FALSE, NULL, 'Sunbiz', 'sunbiz.org', TRUE, 2, '$400 late fee for annual report', 'dos.fl.gov/sunbiz/forms/fees/'),
('GA', 'Georgia', 11000, 600000, 'annual', 11000, 600000, 'annual', 23500, 23500, 1000000, 'same-day', 250000, 120, FALSE, NULL, FALSE, NULL, NULL, FALSE, NULL, 'GA SOS', 'sos.ga.gov', TRUE, 7, NULL, 'sos.ga.gov/corporations-division'),
('HI', 'Hawaii', 5000, 150000, 'annual', 5000, 150000, 'annual', 5000, 5000, 250000, 'expedited', 100000, 120, FALSE, NULL, FALSE, NULL, NULL, FALSE, NULL, 'HI BREG', 'cca.hawaii.gov/breg', TRUE, 7, NULL, 'cca.hawaii.gov/breg'),
('ID', 'Idaho', 10000, NULL, 'annual', 10000, NULL, 'annual', 10000, 10000, 200000, 'expedited', 200000, 120, FALSE, NULL, FALSE, NULL, NULL, FALSE, NULL, 'ID SOS', 'sos.idaho.gov', TRUE, 5, 'Annual report required but $0 fee', 'sos.idaho.gov/business'),
('IL', 'Illinois', 15000, 750000, 'annual', 15000, 750000, 'annual', 15000, 17500, 5000000, 'same-day', 250000, 90, FALSE, NULL, FALSE, NULL, NULL, FALSE, NULL, 'IL SOS', 'ilsos.gov', TRUE, 5, NULL, 'ilsos.gov/departments/business_services'),
('IN', 'Indiana', 9500, 310000, 'biennial', 9500, 310000, 'biennial', 9500, 9500, 1000000, '24-hour', 200000, 120, FALSE, NULL, FALSE, NULL, NULL, FALSE, NULL, 'IN SOS', 'in.gov/sos/business', TRUE, 5, NULL, 'in.gov/sos/business'),
('IA', 'Iowa', 5000, 300000, 'biennial', 5000, 600000, 'biennial', 10000, 10000, 250000, '24-hour', 100000, 120, FALSE, NULL, FALSE, NULL, NULL, FALSE, NULL, 'IA SOS', 'sos.iowa.gov', TRUE, 5, NULL, 'sos.iowa.gov/business'),
('KS', 'Kansas', 16000, 500000, 'annual', 9000, 550000, 'annual', 16500, 11500, 400000, 'rush', 300000, 120, FALSE, NULL, FALSE, NULL, NULL, FALSE, NULL, 'KS SOS', 'sos.ks.gov', TRUE, 5, NULL, 'sos.ks.gov/business'),
('KY', 'Kentucky', 4000, 150000, 'annual', 4000, 150000, 'annual', 9000, 9000, 500000, 'same-day', 150000, 120, FALSE, NULL, FALSE, NULL, NULL, FALSE, NULL, 'KY SOS', 'sos.ky.gov', TRUE, 3, 'One of the cheapest states', 'sos.ky.gov/bus'),
('LA', 'Louisiana', 10000, 350000, 'annual', 7500, 350000, 'annual', 15000, 15000, 500000, 'same-day', 250000, 60, FALSE, NULL, FALSE, NULL, NULL, FALSE, NULL, 'LA SOS', 'sos.la.gov', TRUE, 5, 'Initial report due within 90 days', 'sos.la.gov/BusinessServices'),
('ME', 'Maine', 17500, 850000, 'annual', 14500, 850000, 'annual', 25000, 25000, 1000000, 'same-day', 200000, 120, FALSE, NULL, FALSE, NULL, NULL, FALSE, NULL, 'ME SOS', 'maine.gov/sos/cec/corp', TRUE, 7, NULL, 'maine.gov/sos/cec/corp'),
('MD', 'Maryland', 10000, 3000000, 'annual', 17000, 3000000, 'annual', 10000, 17000, 500000, 'same-day', 250000, 120, FALSE, NULL, FALSE, NULL, NULL, FALSE, NULL, 'MD SDAT', 'dat.maryland.gov', TRUE, 7, 'Expensive ongoing: $300/yr annual report', 'dat.maryland.gov/businesses'),
('MA', 'Massachusetts', 50000, 5000000, 'annual', 27500, 1250000, 'annual', 50000, 30000, 750000, 'expedited', 300000, 60, FALSE, NULL, FALSE, NULL, NULL, FALSE, NULL, 'MA SOC', 'sec.state.ma.us/cor', TRUE, 5, 'Most expensive state for LLC formation + annual', 'sec.state.ma.us/cor'),
('MI', 'Michigan', 5000, 250000, 'annual', 6000, 250000, 'annual', 5000, 6000, 1000000, 'same-day', 250000, 120, FALSE, NULL, FALSE, NULL, NULL, FALSE, NULL, 'MI LARA', 'michigan.gov/lara', TRUE, 5, '$1000 for 1-hour rush', 'michigan.gov/lara'),
('MN', 'Minnesota', 15500, NULL, NULL, 15500, NULL, NULL, 15500, 15500, NULL, NULL, 350000, 120, FALSE, NULL, FALSE, NULL, NULL, FALSE, NULL, 'MN SOS', 'sos.state.mn.us', TRUE, 3, 'No RA required; no annual fee', 'sos.state.mn.us/business-liens'),
('MS', 'Mississippi', 5000, NULL, NULL, 5000, NULL, NULL, 25000, 25000, 500000, '24-hour', 250000, 180, FALSE, NULL, FALSE, NULL, NULL, FALSE, NULL, 'MS SOS', 'sos.ms.gov', TRUE, 5, 'No annual report for LLCs', 'sos.ms.gov/business-services'),
('MO', 'Missouri', 5000, NULL, NULL, 5800, NULL, NULL, 10500, 10500, 500000, '24-hour', 250000, 60, FALSE, NULL, FALSE, NULL, NULL, FALSE, NULL, 'MO SOS', 'sos.mo.gov/business', TRUE, 5, 'No annual report or fee for LLCs', 'sos.mo.gov/business'),
('MT', 'Montana', 3500, 200000, 'annual', 7000, 200000, 'annual', 3500, 7000, 200000, 'expedited', 100000, 120, FALSE, NULL, FALSE, NULL, NULL, FALSE, NULL, 'MT SOS', 'sosmt.gov/business', TRUE, 5, 'Cheapest LLC formation in the US', 'sosmt.gov/business'),
('NE', 'Nebraska', 10000, 130000, 'biennial', 10000, 130000, 'biennial', 12000, 10000, NULL, NULL, 300000, 120, FALSE, NULL, FALSE, NULL, NULL, FALSE, NULL, 'NE SOS', 'sos.nebraska.gov', TRUE, 5, NULL, 'sos.nebraska.gov'),
('NV', 'Nevada', 42500, 3500000, 'annual', 72500, 6500000, 'annual', 42500, 42500, 5000000, '2-hour', 250000, 90, FALSE, NULL, FALSE, NULL, NULL, TRUE, 2000000, 'SilverFlume', 'nvsilverflume.gov', TRUE, 3, '$200 LLC biz license + $500 corp biz license; no income tax', 'nvsilverflume.gov'),
('NH', 'New Hampshire', 10000, 1000000, 'annual', 10000, 1000000, 'annual', 10000, 10000, NULL, NULL, 150000, 120, FALSE, NULL, FALSE, NULL, NULL, FALSE, NULL, 'NH SOS', 'sos.nh.gov', TRUE, 7, NULL, 'sos.nh.gov'),
('NJ', 'New Jersey', 12500, 750000, 'annual', 12500, 750000, 'annual', 12500, 12500, 500000, 'same-day', 500000, 120, FALSE, NULL, FALSE, NULL, NULL, FALSE, NULL, 'NJ DORES', 'njportal.com/dor', TRUE, 5, NULL, 'njportal.com/dor'),
('NM', 'New Mexico', 5000, NULL, NULL, 12500, 250000, 'biennial', 10000, 10000, NULL, NULL, 200000, 120, FALSE, NULL, FALSE, NULL, NULL, FALSE, NULL, 'NM SOS', 'sos.nm.gov', TRUE, 5, 'No LLC annual report or fee', 'sos.nm.gov'),
('NY', 'New York', 20000, 90000, 'biennial', 12500, 90000, 'biennial', 25000, 22500, 5000000, '2-hour', 200000, 60, TRUE, 10000000, FALSE, NULL, 'Corp franchise tax based on income/capital', FALSE, NULL, 'NY DOS', 'dos.ny.gov', TRUE, 7, 'PUBLICATION REQ: 2 newspapers x 6 weeks = $200-$2000+ depending on county', 'dos.ny.gov/business'),
('NC', 'North Carolina', 12500, 2000000, 'annual', 12500, 2000000, 'annual', 25000, 25000, 5000000, 'same-day', 300000, 120, FALSE, NULL, FALSE, NULL, 'Corp: $200 min franchise tax based on net worth', FALSE, NULL, 'NC SOS', 'sosnc.gov', TRUE, 5, NULL, 'sosnc.gov'),
('ND', 'North Dakota', 13500, 500000, 'annual', 10000, 250000, 'annual', 13500, 13500, NULL, NULL, 100000, 365, FALSE, NULL, FALSE, NULL, NULL, FALSE, NULL, 'ND SOS', 'sos.nd.gov', TRUE, 7, NULL, 'sos.nd.gov'),
('OH', 'Ohio', 9900, NULL, NULL, 9900, NULL, NULL, 9900, 9900, NULL, NULL, 390000, 180, FALSE, NULL, FALSE, NULL, NULL, FALSE, NULL, 'OH SOS', 'ohiosos.gov', TRUE, 5, 'No annual reports or fees at all', 'ohiosos.gov'),
('OK', 'Oklahoma', 10000, 250000, 'annual', 5000, NULL, NULL, 30000, 30000, NULL, NULL, 100000, 60, FALSE, NULL, FALSE, NULL, NULL, FALSE, NULL, 'OK SOS', 'sos.ok.gov', TRUE, 5, NULL, 'sos.ok.gov'),
('OR', 'Oregon', 10000, 1000000, 'annual', 10000, 500000, 'annual', 27500, 27500, 1000000, 'same-day', 1000000, 120, FALSE, NULL, FALSE, NULL, NULL, FALSE, NULL, 'OR SOS', 'sos.oregon.gov', TRUE, 5, NULL, 'sos.oregon.gov'),
('PA', 'Pennsylvania', 12500, 70000, 'annual', 12500, 70000, 'annual', 25000, 25000, 3000000, 'same-day', 700000, 120, FALSE, NULL, FALSE, NULL, NULL, FALSE, NULL, 'PA DOS', 'dos.pa.gov', TRUE, 7, '$7/yr annual report (new 2025)', 'dos.pa.gov'),
('RI', 'Rhode Island', 15000, 500000, 'annual', 23000, 500000, 'annual', 15000, 15000, NULL, NULL, 500000, 120, FALSE, NULL, FALSE, NULL, 'Corp: $400 min annual tax', FALSE, NULL, 'RI SOS', 'sos.ri.gov', TRUE, 7, NULL, 'sos.ri.gov'),
('SC', 'South Carolina', 11000, NULL, NULL, 13500, 250000, 'annual', 11000, 11000, 500000, '24-hour', 250000, 120, FALSE, NULL, FALSE, NULL, 'Corp: $25 min annual license fee', FALSE, NULL, 'SC SOS', 'sos.sc.gov', TRUE, 5, 'No LLC annual report', 'sos.sc.gov'),
('SD', 'South Dakota', 15000, 550000, 'annual', 15000, 500000, 'annual', 75000, 75000, NULL, NULL, 250000, 120, FALSE, NULL, FALSE, NULL, NULL, FALSE, NULL, 'SD SOS', 'sdsos.gov', TRUE, 5, '$750 foreign LLC fee (highest)', 'sdsos.gov'),
('TN', 'Tennessee', 30000, 3000000, 'annual', 10000, 200000, 'annual', 30000, 30000, 5000000, '24-hour', 200000, 120, FALSE, NULL, FALSE, NULL, 'Corp: $100 min franchise tax based on net worth', FALSE, NULL, 'TN SOS', 'sos.tn.gov', TRUE, 5, 'LLC fees are $50/member with $300 min', 'sos.tn.gov'),
('TX', 'Texas', 30000, NULL, NULL, 30000, NULL, NULL, 75000, 75000, 500000, 'same-day', 400000, 120, FALSE, NULL, TRUE, 0, 'Franchise tax only if revenue >$2.47M; PIR required May 15', FALSE, NULL, 'SOSDirect', 'direct.sos.state.tx.us', TRUE, 3, 'No income tax; $750 foreign LLC fee', 'sos.state.tx.us'),
('UT', 'Utah', 5900, 180000, 'annual', 5900, 180000, 'annual', 7000, 7000, 750000, 'same-day', 220000, 120, FALSE, NULL, FALSE, NULL, NULL, FALSE, NULL, 'UT DCC', 'corporations.utah.gov', TRUE, 3, 'Cheapest overall for formation + ongoing', 'corporations.utah.gov'),
('VT', 'Vermont', 15500, 450000, 'annual', 15500, 600000, 'annual', 12500, 12500, NULL, NULL, 200000, 120, FALSE, NULL, FALSE, NULL, NULL, FALSE, NULL, 'VT SOS', 'sos.vermont.gov', TRUE, 7, NULL, 'sos.vermont.gov'),
('VA', 'Virginia', 10000, 500000, 'annual', 7500, 250000, 'annual', 10000, 10000, 2000000, '2-hour', 100000, 120, FALSE, NULL, FALSE, NULL, 'Stock corp: $100 min/yr based on shares', FALSE, NULL, 'VA SCC', 'scc.virginia.gov', TRUE, 3, NULL, 'scc.virginia.gov'),
('WA', 'Washington', 20000, 600000, 'annual', 19000, 700000, 'annual', 20000, 18000, 500000, 'same-day', 300000, 180, FALSE, NULL, FALSE, NULL, 'B&O gross receipts tax (not formation-related)', FALSE, NULL, 'CCFS', 'ccfs.sos.wa.gov', TRUE, 3, 'No income tax; B&O tax applies', 'ccfs.sos.wa.gov'),
('WV', 'West Virginia', 10000, 250000, 'annual', 10000, 250000, 'annual', 15000, 15000, 250000, '24-hour', 150000, 120, FALSE, NULL, FALSE, NULL, NULL, FALSE, NULL, 'WV SOS', 'sos.wv.gov', TRUE, 5, NULL, 'sos.wv.gov'),
('WI', 'Wisconsin', 13000, 250000, 'annual', 10000, 250000, 'annual', 10000, 10000, 250000, 'same-day', 150000, 120, FALSE, NULL, FALSE, NULL, NULL, FALSE, NULL, 'WI DFI', 'dfi.wi.gov', TRUE, 3, NULL, 'dfi.wi.gov'),
('WY', 'Wyoming', 10000, 600000, 'annual', 10000, 600000, 'annual', 10000, 10000, 1000000, 'same-day', 500000, 120, FALSE, NULL, FALSE, NULL, NULL, FALSE, NULL, 'WyoBiz', 'wyobiz.wyo.gov', TRUE, 2, 'No income tax; privacy-friendly; no member/manager names on public filings', 'wyobiz.wyo.gov'),
('DC', 'District of Columbia', 9900, 3000000, 'biennial', 9900, 3000000, 'biennial', 9900, 9900, NULL, NULL, 250000, 120, FALSE, NULL, FALSE, NULL, NULL, FALSE, NULL, 'DC DLCP', 'dcra.dc.gov', TRUE, 5, '$300 biennial report', 'dcra.dc.gov');

COMMIT;
