-- Migration 036: Extend company_profiles with systems, AI, legal context
-- Adds structured JSONB fields for document generation and compliance automation

BEGIN;

-- ============================================================================
-- 1. JSONB fields for systems & document sources
-- ============================================================================

ALTER TABLE compliance_company_profiles
    ADD COLUMN IF NOT EXISTS repos JSONB DEFAULT '[]'::jsonb,
    ADD COLUMN IF NOT EXISTS document_sources JSONB DEFAULT '[]'::jsonb,
    ADD COLUMN IF NOT EXISTS processing_systems JSONB DEFAULT '[]'::jsonb,
    ADD COLUMN IF NOT EXISTS ai_systems JSONB DEFAULT '[]'::jsonb,
    ADD COLUMN IF NOT EXISTS technical_contacts JSONB DEFAULT '[]'::jsonb;

-- ============================================================================
-- 2. Regulatory booleans
-- ============================================================================

ALTER TABLE compliance_company_profiles
    ADD COLUMN IF NOT EXISTS subject_to_nis2 BOOLEAN DEFAULT FALSE,
    ADD COLUMN IF NOT EXISTS subject_to_ai_act BOOLEAN DEFAULT FALSE,
    ADD COLUMN IF NOT EXISTS subject_to_iso27001 BOOLEAN DEFAULT FALSE;

-- ============================================================================
-- 3. Supervisory authority & review cycle
-- ============================================================================

ALTER TABLE compliance_company_profiles
    ADD COLUMN IF NOT EXISTS supervisory_authority VARCHAR(255),
    ADD COLUMN IF NOT EXISTS review_cycle_months INTEGER DEFAULT 12;

COMMIT;
