{
  "$schema": "https://docs.oasis-open.org/csaf/csaf/v2.1/schema/extension-metaschema.json",
  "$id": "https://gcve.eu/schema/csaf/extensions/gcve-bcp-05-x-01_1.0.0.json",
  "title": "GCVE BCP-05-X-01 AI-Assisted Vulnerability Information Annotation for CSAF",
  "description": "Template CSAF 2.1 extension schema for carrying GCVE BCP-05-X-01 source x_gcve data at the vulnerability extension point. Replace the $id with the hosted schema URI before production publication.",
  "type": "object",
  "required": ["$schema", "category", "content", "critical"],
  "properties": {
    "$schema": {
      "const": "https://gcve.eu/schema/csaf/extensions/gcve-bcp-05-x-01_1.0.0.json"
    },
    "category": {
      "const": "informational"
    },
    "critical": {
      "const": false
    },
    "content": {
      "type": "object",
      "required": ["x_gcve"],
      "properties": {
        "x_gcve": {
          "type": "array",
          "minItems": 1,
          "items": {"$ref": "#/$defs/gcveWrapper"}
        }
      },
      "additionalProperties": false
    }
  },
  "additionalProperties": false,
  "$defs": {
    "gcveWrapper": {
      "type": "object",
      "required": ["extensions"],
      "properties": {
        "extensions": {
          "type": "object",
          "required": ["bcp-05-x-01"],
          "properties": {
            "bcp-05-x-01": {"$ref": "#/$defs/bcp05x01"}
          },
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    },
    "bcp05x01": {
      "type": "object",
      "required": ["ai_annotations"],
      "properties": {
        "ai_annotations": {
          "type": "array",
          "minItems": 1,
          "items": {"$ref": "#/$defs/aiAnnotation"}
        }
      },
      "additionalProperties": false
    },
    "aiAnnotation": {
      "type": "object",
      "required": ["scope", "ai_level"],
      "properties": {
        "scope": {"enum": ["record", "field"]},
        "field_name": {"type": "string", "minLength": 1},
        "tags": {
          "type": "array",
          "items": {"type": "string", "minLength": 1},
          "uniqueItems": true
        },
        "description": {"type": "string"},
        "ai_level": {"enum": ["none", "assisted", "augmented", "generated"]},
        "review_status": {"enum": ["none", "partial", "full"]},
        "models": {
          "type": "array",
          "items": {"$ref": "#/$defs/model"}
        }
      },
      "allOf": [
        {
          "if": {"properties": {"scope": {"const": "field"}}, "required": ["scope"]},
          "then": {"required": ["field_name"]},
          "else": {"not": {"required": ["field_name"]}}
        },
        {
          "if": {"properties": {"ai_level": {"const": "none"}}, "required": ["ai_level"]},
          "then": {
            "not": {
              "anyOf": [
                {"required": ["review_status"]},
                {"required": ["models"]}
              ]
            }
          }
        }
      ],
      "additionalProperties": false
    },
    "model": {
      "type": "object",
      "required": ["name"],
      "properties": {
        "name": {"type": "string", "minLength": 1},
        "version": {"type": "string", "minLength": 1},
        "provider": {"type": "string", "minLength": 1},
        "source": {"enum": ["ollama", "huggingface", "local", "other"]},
        "identifier": {"type": "string", "minLength": 1},
        "url": {"type": "string", "format": "uri"}
      },
      "additionalProperties": false
    }
  }
}
