-- 048: Form 499-A intake fields
--
-- The 2026 Form 499-A (reporting 2025 revenues) requires carrier data
-- beyond what migration 043 captured for the RMD letter. These fields
-- back Block 1 (Lines 106-112), Block 2 (Lines 203-218), Block 2-C
-- (Lines 221-228), and Block 6 (Lines 603-604) of the real form.
--
-- Block/line references per 2026-FCC-Form-499A-Form-Instructions.pdf
-- (November 2025 release).

-- ── Block 1: Filer Identification (Lines 106, 108, 112) ──────────────────
-- Line 106: affiliated filer / holding company
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS affiliated_filer_name  TEXT;
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS affiliated_filer_ein   TEXT;
-- Line 108: management company
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS management_company_name TEXT;
-- Line 112: all trade names used in past 3 years (including predecessors)
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS trade_names TEXT[] DEFAULT '{}';

-- ── Block 2-A: Regulatory contact (Lines 203-208) ────────────────────────
-- Line 203-206: Person who completed the worksheet — defaults to Performance
-- West (Justin Hannah) as the regulatory contact for managed filers.
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS regulatory_contact_name    TEXT
    DEFAULT 'Justin Hannah';
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS regulatory_contact_email   TEXT
    DEFAULT 'justin@performancewest.net';
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS regulatory_contact_phone   TEXT
    DEFAULT '888-411-0383';
-- Line 207: corporate office for future worksheets — defaults to PW address
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS worksheet_office_company   TEXT
    DEFAULT 'Performance West Inc';
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS worksheet_office_street    TEXT
    DEFAULT '30 N Gould St, Ste N';
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS worksheet_office_city      TEXT
    DEFAULT 'Sheridan';
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS worksheet_office_state     TEXT
    DEFAULT 'WY';
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS worksheet_office_zip       TEXT
    DEFAULT '82801';
-- Line 208: billing address — customer (nullable, defaults to entity address)
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS billing_contact_name       TEXT;
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS billing_contact_email      TEXT;
-- Line 208.1: separate email for ITSP regulatory fee correspondence
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS itsp_regulatory_fee_email  TEXT;

-- ── Block 2-B: D.C. Agent (Lines 209-218) — defaults to Northwest RA ─────
-- Hardcoded on DCAgentHandler; stored here so 499-A prep can read it.
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS dc_agent_company TEXT
    DEFAULT 'Northwest Registered Agent Service Inc.';
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS dc_agent_street  TEXT
    DEFAULT '1717 N Street NW STE 1';
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS dc_agent_city    TEXT
    DEFAULT 'Washington';
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS dc_agent_state   TEXT
    DEFAULT 'DC';
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS dc_agent_zip     TEXT
    DEFAULT '20036';
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS dc_agent_phone   TEXT
    DEFAULT '509-768-2249';
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS dc_agent_email   TEXT
    DEFAULT 'support@northwestregisteredagent.com';

-- ── Block 2-C: Officers (Lines 221, 223, 225) + Jurisdictions (227) + First-service (228) ──
-- We already track ceo_name/ceo_title (Line 221). Add Officer 2 and Officer 3.
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS officer_2_name    TEXT;
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS officer_2_title   TEXT;
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS officer_2_street  TEXT;
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS officer_2_city    TEXT;
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS officer_2_state   TEXT;
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS officer_2_zip     TEXT;

ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS officer_3_name    TEXT;
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS officer_3_title   TEXT;
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS officer_3_street  TEXT;
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS officer_3_city    TEXT;
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS officer_3_state   TEXT;
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS officer_3_zip     TEXT;

-- Line 227: multi-select jurisdictions where service provided/will be provided
-- (past 15 mo + next 12 mo). Store as array of state/territory codes.
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS jurisdictions_served TEXT[] DEFAULT '{}';

-- Line 228: year + month first provided telecom service
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS first_telecom_service_year  INT;
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS first_telecom_service_month INT
    CHECK (first_telecom_service_month IS NULL OR first_telecom_service_month BETWEEN 1 AND 12);
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS first_telecom_service_pre_1999 BOOLEAN DEFAULT FALSE;

-- ── Block 6: Exemption certifications (Lines 603, 604) ───────────────────
-- Line 603: exempt from each mechanism? (usf/trs/nanpa/lnp)
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS exempt_usf    BOOLEAN DEFAULT FALSE;
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS exempt_trs    BOOLEAN DEFAULT FALSE;
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS exempt_nanpa  BOOLEAN DEFAULT FALSE;
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS exempt_lnp    BOOLEAN DEFAULT FALSE;
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS exemption_explanation TEXT;
-- Line 604: state/local gov entity? 501(c) tax exempt?
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS is_state_local_gov    BOOLEAN DEFAULT FALSE;
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS is_tax_exempt_501c    BOOLEAN DEFAULT FALSE;

-- ── NECA OCN tracking (supports the new ocn-registration service) ────────
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS ocn                  TEXT;
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS ocn_category         TEXT
    CHECK (ocn_category IS NULL OR ocn_category IN ('CAP','ETHX','CLEC','IC','IPES','LRSL','PCS','PCSR','ULEC','WIRE','WRSL'));
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS ocn_assigned_at      TIMESTAMPTZ;
