{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://agrodt.github.io/agrotool-knowledge-portal/schemas/v4/component_version_contexts.schema.json",
  "title": "PublicComponentVersionContextsV4",
  "type": "array",
  "items": {
    "type": "object",
    "allOf": [
      { "$ref": "../v1/common.schema.json#/$defs/recordMetadata" },
      {
        "type": "object",
        "required": [
          "component_version_context_id",
          "component_id",
          "line",
          "target_version",
          "version_scheme",
          "labels",
          "is_default",
          "evidence_hierarchy_version",
          "evidence_summary_ids",
          "source_ids",
          "limitations"
        ],
        "properties": {
          "component_version_context_id": {
            "type": "string",
            "pattern": "^CVC[A-Z0-9_-]{1,60}$"
          },
          "component_id": {
            "type": "string",
            "pattern": "^CMP[A-Z0-9_-]{1,61}$"
          },
          "line": {
            "$ref": "../v3/component_state_events.schema.json#/$defs/systemLine"
          },
          "target_version": { "type": "string", "minLength": 1 },
          "version_scheme": { "enum": ["semver", "opaque"] },
          "labels": {
            "$ref": "../v1/common.schema.json#/$defs/localizedText"
          },
          "is_default": { "type": "boolean" },
          "evidence_hierarchy_version": {
            "type": "string",
            "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$"
          },
          "evidence_summary_ids": {
            "allOf": [
              { "$ref": "../v1/common.schema.json#/$defs/evidenceIds" },
              { "type": "array", "minItems": 1 }
            ]
          },
          "source_ids": {
            "allOf": [
              { "$ref": "../v1/common.schema.json#/$defs/sourceIds" },
              { "type": "array", "minItems": 1 }
            ]
          },
          "limitations": {
            "$ref": "../v1/common.schema.json#/$defs/localizedText"
          }
        }
      }
    ],
    "required": [
      "record_version",
      "public_status",
      "provenance_class",
      "license_class",
      "last_verified_at",
      "component_version_context_id",
      "component_id",
      "line",
      "target_version",
      "version_scheme",
      "labels",
      "is_default",
      "evidence_hierarchy_version",
      "evidence_summary_ids",
      "source_ids",
      "limitations"
    ],
    "properties": {
      "record_version": {
        "$ref": "../v1/common.schema.json#/$defs/recordVersion"
      },
      "public_status": {
        "$ref": "../v1/common.schema.json#/$defs/publicStatus"
      },
      "provenance_class": {
        "$ref": "../v1/common.schema.json#/$defs/provenanceClass"
      },
      "license_class": {
        "$ref": "../v1/common.schema.json#/$defs/licenseClass"
      },
      "last_verified_at": {
        "$ref": "../v1/common.schema.json#/$defs/date"
      },
      "valid_from": { "$ref": "../v1/common.schema.json#/$defs/date" },
      "valid_to": {
        "anyOf": [
          { "$ref": "../v1/common.schema.json#/$defs/date" },
          { "type": "null" }
        ]
      },
      "component_version_context_id": {
        "type": "string",
        "pattern": "^CVC[A-Z0-9_-]{1,60}$"
      },
      "component_id": {
        "type": "string",
        "pattern": "^CMP[A-Z0-9_-]{1,61}$"
      },
      "line": {
        "$ref": "../v3/component_state_events.schema.json#/$defs/systemLine"
      },
      "target_version": { "type": "string", "minLength": 1 },
      "version_scheme": { "enum": ["semver", "opaque"] },
      "labels": { "$ref": "../v1/common.schema.json#/$defs/localizedText" },
      "is_default": { "type": "boolean" },
      "evidence_hierarchy_version": {
        "type": "string",
        "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$"
      },
      "evidence_summary_ids": {
        "allOf": [
          { "$ref": "../v1/common.schema.json#/$defs/evidenceIds" },
          { "type": "array", "minItems": 1 }
        ]
      },
      "source_ids": {
        "allOf": [
          { "$ref": "../v1/common.schema.json#/$defs/sourceIds" },
          { "type": "array", "minItems": 1 }
        ]
      },
      "limitations": {
        "$ref": "../v1/common.schema.json#/$defs/localizedText"
      }
    },
    "if": {
      "properties": { "version_scheme": { "const": "semver" } },
      "required": ["version_scheme"]
    },
    "then": {
      "properties": {
        "target_version": {
          "type": "string",
          "pattern": "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(?:-[0-9A-Za-z.-]+)?(?:\\+[0-9A-Za-z.-]+)?$"
        }
      }
    },
    "unevaluatedProperties": false
  }
}
