{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://agrodt.github.io/agrotool-knowledge-portal/schemas/v3/component_mappings.schema.json",
  "title": "PublicComponentMappingsV3",
  "type": "array",
  "items": {
    "type": "object",
    "allOf": [
      { "$ref": "../v1/common.schema.json#/$defs/recordMetadata" },
      {
        "type": "object",
        "required": [
          "component_mapping_id",
          "component_id",
          "line",
          "target_kind",
          "target_id",
          "version_applicability",
          "mapping_status",
          "confidence",
          "evidence_summary_ids",
          "source_ids",
          "derivation_method",
          "derivation_version"
        ],
        "properties": {
          "component_mapping_id": {
            "type": "string",
            "pattern": "^CM[A-Z0-9_-]{2,62}$"
          },
          "component_id": {
            "type": "string",
            "pattern": "^CMP[A-Z0-9_-]{1,61}$"
          },
          "line": { "$ref": "#/$defs/systemLine" },
          "target_kind": {
            "enum": [
              "software_module",
              "software_artifact",
              "topic",
              "dataset",
              "validation_record",
              "external_record"
            ]
          },
          "target_id": {
            "type": "string",
            "pattern": "^[A-Za-z0-9][A-Za-z0-9._:/+-]{0,127}$"
          },
          "version_applicability": {
            "$ref": "#/$defs/versionApplicability"
          },
          "mapping_status": {
            "enum": ["source_asserted", "candidate", "deprecated"]
          },
          "confidence": {
            "type": ["string", "null"],
            "enum": ["low", "medium", "high", null]
          },
          "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 }
            ]
          },
          "derivation_method": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]*$"
          },
          "derivation_version": { "type": "string", "minLength": 1 }
        }
      }
    ],
    "unevaluatedProperties": false
  },
  "$defs": {
    "systemLine": {
      "enum": ["scientific_model", "software", "data", "validation"]
    },
    "versionId": {
      "type": "string",
      "pattern": "^[A-Za-z0-9][A-Za-z0-9._+-]{0,63}$"
    },
    "versionApplicability": {
      "oneOf": [
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["kind", "version"],
          "properties": {
            "kind": { "const": "exact" },
            "version": { "$ref": "#/$defs/versionId" }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["kind", "from", "to"],
          "properties": {
            "kind": { "const": "range" },
            "from": { "$ref": "#/$defs/versionId" },
            "to": { "$ref": "#/$defs/versionId" }
          }
        }
      ]
    }
  }
}
