{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://agrodt.github.io/agrotool-knowledge-portal/schemas/v3/gap_candidates.schema.json",
  "title": "PublicGapCandidatesV3",
  "type": "array",
  "items": {
    "type": "object",
    "allOf": [
      { "$ref": "../v1/common.schema.json#/$defs/recordMetadata" },
      {
        "type": "object",
        "required": [
          "gap_candidate_id",
          "gap_type",
          "component_ids",
          "affected_lines",
          "observations",
          "rule_id",
          "rule_version",
          "input_release_id",
          "input_sha256",
          "lifecycle_status",
          "created_at",
          "status_changed_at",
          "archive_reason",
          "replacement_gap_ids",
          "evidence_summary_ids",
          "source_ids",
          "limitations"
        ],
        "properties": {
          "gap_candidate_id": {
            "type": "string",
            "pattern": "^GAP[A-Z0-9_-]{1,60}$"
          },
          "gap_type": {
            "enum": [
              "coverage_gap_candidate",
              "research_gap_candidate",
              "engineering_opportunity",
              "data_gap_candidate",
              "validation_gap_candidate"
            ]
          },
          "component_ids": {
            "type": "array",
            "minItems": 1,
            "items": {
              "type": "string",
              "pattern": "^CMP[A-Z0-9_-]{1,61}$"
            },
            "uniqueItems": true
          },
          "affected_lines": {
            "type": "array",
            "minItems": 1,
            "items": {
              "enum": ["scientific_model", "software", "data", "validation"]
            },
            "uniqueItems": true
          },
          "observations": {
            "type": "array",
            "minItems": 1,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": ["observation_type", "value"],
              "properties": {
                "observation_type": {
                  "type": "string",
                  "pattern": "^[a-z][a-z0-9_]*$"
                },
                "value": { "type": ["string", "number", "boolean"] }
              }
            }
          },
          "rule_id": { "type": "string", "pattern": "^[a-z][a-z0-9_]*$" },
          "rule_version": { "type": "string", "minLength": 1 },
          "input_release_id": {
            "type": "string",
            "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+(?:-[0-9A-Za-z.-]+)?\\+[0-9]{8}$"
          },
          "input_sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
          "lifecycle_status": {
            "enum": [
              "active",
              "resolved",
              "rejected",
              "reclassified",
              "algorithm_or_corpus_changed"
            ]
          },
          "created_at": { "type": "string", "format": "date" },
          "status_changed_at": {
            "type": ["string", "null"],
            "format": "date"
          },
          "archive_reason": { "type": ["string", "null"] },
          "replacement_gap_ids": {
            "type": "array",
            "items": {
              "type": "string",
              "pattern": "^GAP[A-Z0-9_-]{1,60}$"
            },
            "uniqueItems": true
          },
          "evidence_summary_ids": {
            "$ref": "../v1/common.schema.json#/$defs/evidenceIds"
          },
          "source_ids": {
            "allOf": [
              { "$ref": "../v1/common.schema.json#/$defs/sourceIds" },
              { "type": "array", "minItems": 1 }
            ]
          },
          "limitations": {
            "$ref": "../v1/common.schema.json#/$defs/localizedText"
          }
        },
        "allOf": [
          {
            "if": {
              "properties": { "lifecycle_status": { "const": "active" } }
            },
            "then": {
              "properties": {
                "status_changed_at": { "type": "null" },
                "archive_reason": { "type": "null" }
              }
            },
            "else": {
              "properties": {
                "status_changed_at": { "type": "string", "format": "date" },
                "archive_reason": { "type": "string", "minLength": 1 }
              }
            }
          }
        ]
      }
    ],
    "unevaluatedProperties": false
  }
}
