-- 045: FACS (Foreign Adversary Control System) intake fields
--
-- Captures data needed for Schedule A/B/C determination and
-- foreign adversary ownership disclosure under 47 CFR 1.80003.
-- Effective June 9, 2026 (FCC 26-2, GN Docket No. 25-166).

-- Foreign adversary control attestation
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS facs_schedule TEXT
    CHECK (facs_schedule IN ('A', 'B', 'C'));

-- Does this entity have any foreign adversary ownership or control?
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS facs_has_foreign_adversary BOOLEAN;

-- FACS attestation filing status
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS facs_filing_status TEXT
    CHECK (facs_filing_status IN (
        'not_required',         -- Schedule C / exempt
        'pending',              -- needs to file
        'filed_no',             -- filed attestation: no foreign adversary control
        'filed_yes',            -- filed attestation: yes (Schedule B disclosure required)
        'disclosure_filed'      -- Schedule B detailed disclosure submitted
    ));

-- Foreign ownership details (JSONB for flexibility)
-- Structure:
-- {
--   "has_foreign_owners": true/false,
--   "foreign_adversary_nexus": true/false,
--   "ownership_interests": [
--     {
--       "holder_name": "Entity Name",
--       "holder_country": "CN",
--       "interest_type": "equity|voting|board|contractual",
--       "interest_pct": 15.0,
--       "is_direct": true/false,
--       "is_foreign_adversary": true/false,
--       "description": "15% equity via holding company XYZ Ltd"
--     }
--   ],
--   "control_mechanisms": ["board_seats", "veto_rights", "management_agreement"],
--   "section_214_auth": true/false,
--   "covered_authorizations": ["section_214_domestic", "section_214_international"],
--   "facs_notes": "Additional context..."
-- }
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS facs_ownership_data JSONB DEFAULT '{}';

-- Covered authorization types held by this entity
-- Used for Schedule A/B/C determination
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS covered_authorizations TEXT[]
    DEFAULT '{}';

-- Section 214 authorization (key determinant for Schedule A)
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS has_section_214 BOOLEAN DEFAULT FALSE;

-- Filing timestamp
ALTER TABLE telecom_entities ADD COLUMN IF NOT EXISTS facs_filed_at TIMESTAMPTZ;
