{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://schemas.oda3.org/uaif/core/v1.0/uaif-core-v1.0.json",
  "title": "UAIF Core Profile Schema v1.0",
  "$comment": "Normative errata build. Authority chain: TCR-STD-002 semantics -> TCR-STD-003 schema spec -> this canonical schema -> /fixtures -> COM-012. See ODA3-2026-08-ERR-UAIF-001.",
  "type": "object",
  "required": [
    "incident_uuid",
    "incident_title",
    "incident_summary",
    "reporting_timestamp",
    "deduplication_hash",
    "remediation_status",
    "record_type",
    "profile",
    "root_cause_primary_domain",
    "root_cause_specific_type",
    "sector_code",
    "jurisdiction_country_code"
  ],
  "properties": {
    "incident_uuid": { "type": "string", "format": "uuid" },
    "incident_title": { "type": "string", "minLength": 5, "maxLength": 255 },
    "incident_summary": { "type": "string", "minLength": 20, "maxLength": 4000 },
    "reporting_timestamp": { "type": "string", "format": "date-time" },
    "reporter_confidence_level": { "type": "integer", "minimum": 1, "maximum": 5 },
    "deduplication_hash": { "type": "string", "pattern": "^[a-fA-F0-9]{64}$" },
    "remediation_status": {
      "type": "string",
      "enum": ["Detected", "Investigating", "Mitigated", "Resolved"]
    },

    "record_type": {
      "type": "string",
      "description": "L0. Ontological classification of the record. Two normative values only. Unclassified signals, alerts, telemetry, or investigative leads are not a UAIF record_type; they remain in the originating detection/case-management workflow until classified.",
      "enum": ["Incident", "Vulnerability"]
    },

    "profile": {
      "type": "string",
      "description": "L0. Base conformance depth declared by the record. See 'extensions' for additive specialized capabilities, which are declared separately and do not affect this value.",
      "enum": ["Core", "Enterprise", "Regulatory"]
    },
    "extensions": {
      "type": "array",
      "description": "L0. Optional, additive specialized capability declarations. Extensions never reduce or override base-profile requirements.",
      "items": { "type": "string", "enum": ["SOC_SIEM", "AI_Security"] },
      "uniqueItems": true
    },

    "root_cause_primary_domain": {
      "type": "string",
      "enum": ["Human", "System", "Data", "External"]
    },
    "root_cause_specific_type": {
      "type": "string",
      "pattern": "^(Adversarial_Attack|Prompt_Injection|Model_Poisoning|Data_Poisoning|RAG_Leakage|Hallucination|Agent_Escalation|Policy_Violation|System_Failure|Human_Error|Supply_Chain_Compromise|Unauthorised_Access|Data_Breach|Denial_of_Service|Misuse|x_[A-Za-z0-9_]+)$"
    },
    "root_cause_confidence": { "type": "string", "enum": ["LOW", "MEDIUM", "HIGH"] },
    "exploit_path_description": { "type": "string", "minLength": 20, "maxLength": 4000 },

    "severity_analytical_score": {
      "type": "number",
      "minimum": 0.0,
      "maximum": 10.0,
      "description": "One-decimal-place precision (ROUND_HALF_UP) is a normative semantic/conformance rule per TCR-STD-002 Section 4.4, verified by the reference implementation and conformance tooling -- deliberately NOT enforced via JSON Schema 'multipleOf', since binary floating-point representation of decimal fractions (e.g. 2.8, 5.1, 9.1) can produce false negatives across validator implementations."
    },
    "severity_presentation_score": {
      "type": "number",
      "minimum": 0.0,
      "maximum": 10.0,
      "description": "One-decimal-place precision (ROUND_HALF_UP) is a normative semantic/conformance rule per TCR-STD-002 Section 4.4, verified by the reference implementation and conformance tooling -- deliberately NOT enforced via JSON Schema 'multipleOf', for the same floating-point interoperability reason as severity_analytical_score."
    },
    "severity_level": { "type": "integer", "minimum": 1, "maximum": 5 },
    "severity_rationale": {
      "type": "object",
      "description": "L2. Sole canonical severity explanation. There is no separate severity_justification field in UAIF v1.0 -- superseded, see Section 9 legacy patterns.",
      "required": ["calibration_status"],
      "properties": {
        "dominant_harm": {
          "type": "string",
          "enum": ["Physical_Harm", "Environmental_Harm", "Security_Integrity", "Privacy_Violation", "Financial_Loss", "Psychological_Harm", "Property_Damage", "Reputational_Harm"]
        },
        "dominant_weight": { "type": "number" },
        "secondary_harms": {
          "type": "array",
          "items": {
            "type": "string",
            "enum": ["Physical_Harm", "Environmental_Harm", "Security_Integrity", "Privacy_Violation", "Financial_Loss", "Psychological_Harm", "Property_Damage", "Reputational_Harm"]
          }
        },
        "secondary_contribution": { "type": "number" },
        "context_modifiers_applied": {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["context", "base_value", "contribution_factor", "effective_contribution"],
            "properties": {
              "context": { "type": "string" },
              "base_value": { "type": "number" },
              "contribution_factor": { "type": "number" },
              "effective_contribution": { "type": "number" }
            },
            "additionalProperties": false
          }
        },
        "context_modifier_sum": { "type": "number" },
        "population_multiplier": { "type": "number" },
        "blast_radius_multiplier": { "type": "number" },
        "impact_scale": { "type": "number" },
        "confidence_factor": { "type": "number" },
        "temporal_reduction": { "type": "number" },
        "temporal_adjustment": { "type": "number" },
        "calibration_status": { "type": "string", "enum": ["provisional", "sector_validated", "custom"] },
        "calibration_source": { "type": ["string", "null"], "format": "uri" },
        "weight_provisional_notice": { "type": ["string", "null"] },
        "assumptions": { "type": "array", "items": { "type": "string" } },
        "precision_notes": { "type": "string" }
      },
      "additionalProperties": true
    },

    "harm_acute": { "type": "boolean" },
    "harm_chronic_proxy": { "type": "boolean" },
    "realized_harm_categories": {
      "type": "array",
      "description": "L3 (Extended Harm Characterisation). Required for Incident records only when profile is Enterprise or Regulatory (see conditional rules). Prohibited under Core.",
      "items": {
        "type": "string",
        "enum": ["Physical_Harm", "Environmental_Harm", "Security_Integrity", "Privacy_Violation", "Financial_Loss", "Psychological_Harm", "Property_Damage", "Reputational_Harm"]
      },
      "minItems": 1,
      "uniqueItems": true
    },
    "cumulative_bias_index": { "type": "number", "minimum": 0.0, "maximum": 1.0 },

    "linked_vulnerability_id": { "type": "string", "description": "L4 (Incident-Vulnerability Relationship)." },
    "exposure_duration_hours": { "type": "number", "minimum": 0, "description": "L4 (Incident-Vulnerability Relationship)." },

    "ai_system_type": { "type": "string", "enum": ["LLM", "VLM", "RAG_Pipeline", "Agentic", "Multi_Agent", "Traditional_ML", "Other"] },
    "non_adversarial_failure_type": { "type": "string" },
    "agent_escalation_chain": { "type": "array", "items": { "type": "string" } },
    "mcp_endpoint_ids": { "type": "array", "items": { "type": "string" } },
    "oauth_pivot_chain": { "type": "array", "items": { "type": "string" } },
    "policy_enforcement_point": { "type": "string" },
    "atlas_technique_id": { "type": "string", "pattern": "^AML\\.T[0-9]{4}(\\.[0-9]{3})?$" },

    "sector_code": {
      "type": "string",
      "enum": ["ENERGY", "TRANSPORT", "BANKING", "FINANCIAL_MARKETS", "HEALTH", "DRINKING_WATER", "WASTE_WATER", "DIGITAL_INFRA", "ICT_SERVICES", "PUBLIC_ADMIN", "SPACE", "POSTAL", "WASTE_MGMT", "CHEMICALS", "FOOD", "MANUFACTURING", "TELECOM", "RESEARCH", "OTHER"]
    },
    "nace_code_actual": { "type": "string", "pattern": "^[A-Z](\\d{2}(\\.\\d{1,2})?)?$" },
    "naics_code_actual": { "type": "string", "pattern": "^\\d{2,6}$" },
    "jurisdiction_country_code": { "type": "string", "pattern": "^[A-Z]{2}(-[A-Z0-9]{1,3})?$" },
    "regulatory_obligations": {
      "type": "array",
      "items": { "type": "string", "enum": ["EU_AI_Act_Article_73", "GDPR_Article_33", "NIS2_Article_23", "DORA_Article_19", "Sectoral_Reporting", "None"] },
      "minItems": 1,
      "uniqueItems": true
    },
    "regulatory_trigger": { "type": "boolean" },
    "trigger_confidence": { "type": "string", "enum": ["LOW", "MEDIUM", "HIGH"] },
    "human_review_recommended": { "type": "boolean" },
    "sensitive_data": { "type": "boolean" },
    "critical_sector": { "type": "boolean" },
    "vulnerable_population": { "type": "boolean" },

    "x_extensions": { "type": "object", "additionalProperties": true }
  },

  "allOf": [
    {
      "$comment": "Universal Incident rule: every Incident record, regardless of profile, requires the L2 severity bundle.",
      "if": {
        "properties": { "record_type": { "const": "Incident" } },
        "required": ["record_type"]
      },
      "then": {
        "required": ["severity_analytical_score", "severity_presentation_score", "severity_level", "severity_rationale"]
      }
    },
    {
      "$comment": "Issue 5 (locked, option a): Enterprise/Regulatory Incident records additionally require realized_harm_categories. Core Incident records do not.",
      "if": {
        "properties": {
          "record_type": { "const": "Incident" },
          "profile": { "enum": ["Enterprise", "Regulatory"] }
        },
        "required": ["record_type", "profile"]
      },
      "then": {
        "required": ["realized_harm_categories"]
      }
    },
    {
      "$comment": "Core prohibition: L3/L4 fields are blocked under profile=Core regardless of extensions (extensions only govern L5/mapping fields, not L3/L4).",
      "if": {
        "properties": { "profile": { "const": "Core" } },
        "required": ["profile"]
      },
      "then": {
        "not": {
          "anyOf": [
            { "required": ["harm_acute"] },
            { "required": ["harm_chronic_proxy"] },
            { "required": ["realized_harm_categories"] },
            { "required": ["cumulative_bias_index"] },
            { "required": ["linked_vulnerability_id"] },
            { "required": ["exposure_duration_hours"] }
          ]
        }
      }
    },
    {
      "$comment": "Extension gating: atlas_technique_id requires extensions to explicitly contain SOC_SIEM. Implemented with 'required' on extensions to avoid the absent-property ambiguity flagged during reconciliation.",
      "if": {
        "properties": { "extensions": { "contains": { "const": "SOC_SIEM" } } },
        "required": ["extensions"]
      },
      "else": {
        "not": { "required": ["atlas_technique_id"] }
      }
    },
    {
      "$comment": "Extension gating: L5 generative/agentic/control-plane fields require extensions to explicitly contain AI_Security.",
      "if": {
        "properties": { "extensions": { "contains": { "const": "AI_Security" } } },
        "required": ["extensions"]
      },
      "else": {
        "not": {
          "anyOf": [
            { "required": ["agent_escalation_chain"] },
            { "required": ["mcp_endpoint_ids"] },
            { "required": ["oauth_pivot_chain"] },
            { "required": ["policy_enforcement_point"] },
            { "required": ["ai_system_type"] },
            { "required": ["non_adversarial_failure_type"] }
          ]
        }
      }
    },
    {
      "$comment": "Regulatory trigger requires confidence + human-review companions.",
      "if": {
        "properties": { "regulatory_trigger": {} },
        "required": ["regulatory_trigger"]
      },
      "then": {
        "required": ["trigger_confidence", "human_review_recommended"]
      }
    },
    {
      "$comment": "Adversarial attack root cause requires exploit path description.",
      "if": {
        "properties": { "root_cause_specific_type": { "const": "Adversarial_Attack" } },
        "required": ["root_cause_specific_type"]
      },
      "then": {
        "required": ["exploit_path_description"]
      }
    },
    {
      "$comment": "Provisional calibration requires the provisional notice.",
      "if": {
        "properties": {
          "severity_rationale": {
            "properties": { "calibration_status": { "const": "provisional" } },
            "required": ["calibration_status"]
          }
        },
        "required": ["severity_rationale"]
      },
      "then": {
        "properties": {
          "severity_rationale": { "required": ["weight_provisional_notice"] }
        }
      }
    }
  ],

  "unevaluatedProperties": false
}
