-- Migration 025: Gap Analysis Projects
-- Product profiles for regulatory gap analysis.

CREATE TABLE IF NOT EXISTS compliance.gap_projects (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    tenant_id UUID NOT NULL,
    name VARCHAR(200) NOT NULL,
    description TEXT DEFAULT '',
    product_type VARCHAR(50) NOT NULL DEFAULT 'software',
    technologies JSONB DEFAULT '[]',
    data_processing JSONB DEFAULT '[]',
    markets JSONB DEFAULT '["EU"]',
    connected_to_internet BOOLEAN DEFAULT false,
    has_software_updates BOOLEAN DEFAULT false,
    uses_ai BOOLEAN DEFAULT false,
    processes_personal_data BOOLEAN DEFAULT false,
    is_critical_infra_supplier BOOLEAN DEFAULT false,
    existing_certifications JSONB DEFAULT '[]',
    applied_norms JSONB DEFAULT '[]',
    has_risk_assessment BOOLEAN DEFAULT false,
    has_technical_file BOOLEAN DEFAULT false,
    has_operating_manual BOOLEAN DEFAULT false,
    has_sbom BOOLEAN DEFAULT false,
    has_vuln_management BOOLEAN DEFAULT false,
    has_update_mechanism BOOLEAN DEFAULT false,
    has_incident_response BOOLEAN DEFAULT false,
    has_supply_chain_mgmt BOOLEAN DEFAULT false,
    ce_marking_since VARCHAR(20),
    product_age VARCHAR(20),
    iace_project_id UUID,
    last_analysis_at TIMESTAMPTZ,
    created_at TIMESTAMPTZ DEFAULT NOW(),
    updated_at TIMESTAMPTZ DEFAULT NOW()
);

CREATE INDEX IF NOT EXISTS idx_gap_projects_tenant ON compliance.gap_projects(tenant_id);
