{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:comuvia:schema:0.1:common",
  "title": "Comuvia 0.1 shared definitions",
  "$defs": {
    "schema_version": {
      "type": "string",
      "const": "comuvia/0.1",
      "x-comuvia-code": "unsupported_schema_version"
    },
    "record_type": {
      "type": "string",
      "enum": [
        "resource_snapshot",
        "source_assertion",
        "interpretation",
        "assessment",
        "question",
        "forecast",
        "outcome",
        "evaluation",
        "artifact_descriptor"
      ]
    },
    "identifier": {
      "type": "string",
      "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,199}$",
      "x-comuvia-code": "invalid_identifier"
    },
    "agent": {
      "description": "Who recorded or authored something, as '<role>:<name>'.",
      "type": "string",
      "pattern": "^[a-z][a-z0-9_-]*:[A-Za-z0-9._~:/@+-]+$",
      "x-comuvia-code": "invalid_identifier"
    },
    "code": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9_]*$"
    },
    "text": {
      "type": "string",
      "minLength": 1
    },
    "revision": {
      "type": "integer",
      "minimum": 1
    },
    "data_origin": {
      "type": "string",
      "enum": [
        "observed",
        "synthetic"
      ]
    },
    "timestamp": {
      "description": "RFC 3339 date-time with an explicit offset.",
      "type": "string",
      "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(\\.[0-9]{1,9})?(Z|[+-][0-9]{2}:[0-9]{2})$",
      "x-comuvia-code": "invalid_timestamp",
      "x-comuvia-semantic": "timestamp"
    },
    "date": {
      "type": "string",
      "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$",
      "x-comuvia-code": "invalid_date",
      "x-comuvia-semantic": "date"
    },
    "day_value": {
      "description": "A value known only to day precision. It is never expanded to a timestamp.",
      "type": "object",
      "properties": {
        "date": {
          "$ref": "urn:comuvia:schema:0.1:common#/$defs/date"
        },
        "precision": {
          "type": "string",
          "const": "day"
        }
      },
      "required": [
        "date",
        "precision"
      ],
      "additionalProperties": false
    },
    "time_point": {
      "anyOf": [
        {
          "$ref": "urn:comuvia:schema:0.1:common#/$defs/timestamp"
        },
        {
          "$ref": "urn:comuvia:schema:0.1:common#/$defs/day_value"
        }
      ]
    },
    "period": {
      "description": "Calendar-day period; 'inclusive' states whether 'end' is included.",
      "type": "object",
      "properties": {
        "start": {
          "$ref": "urn:comuvia:schema:0.1:common#/$defs/date"
        },
        "end": {
          "$ref": "urn:comuvia:schema:0.1:common#/$defs/date"
        },
        "inclusive": {
          "type": "boolean"
        },
        "precision": {
          "type": "string",
          "const": "day"
        }
      },
      "required": [
        "start",
        "end",
        "inclusive",
        "precision"
      ],
      "additionalProperties": false,
      "x-comuvia-semantic": "period"
    },
    "unknown_marker": {
      "description": "The value exists but the recorder does not know it.",
      "type": "object",
      "properties": {
        "unknown": {
          "$ref": "urn:comuvia:schema:0.1:common#/$defs/code"
        },
        "note": {
          "$ref": "urn:comuvia:schema:0.1:common#/$defs/text"
        }
      },
      "required": [
        "unknown"
      ],
      "additionalProperties": false,
      "x-comuvia-code": "invalid_marker"
    },
    "withheld_marker": {
      "description": "The value is known but deliberately undisclosed.",
      "type": "object",
      "properties": {
        "withheld": {
          "$ref": "urn:comuvia:schema:0.1:common#/$defs/code"
        },
        "note": {
          "$ref": "urn:comuvia:schema:0.1:common#/$defs/text"
        }
      },
      "required": [
        "withheld"
      ],
      "additionalProperties": false,
      "x-comuvia-code": "invalid_marker"
    },
    "digest": {
      "type": "string",
      "pattern": "^sha256:[0-9a-f]{64}$",
      "x-comuvia-code": "malformed_digest"
    },
    "reference": {
      "type": "object",
      "properties": {
        "record_type": {
          "$ref": "urn:comuvia:schema:0.1:common#/$defs/record_type"
        },
        "id": {
          "$ref": "urn:comuvia:schema:0.1:common#/$defs/identifier"
        },
        "revision": {
          "$ref": "urn:comuvia:schema:0.1:common#/$defs/revision"
        },
        "digest": {
          "$ref": "urn:comuvia:schema:0.1:common#/$defs/digest"
        }
      },
      "required": [
        "record_type",
        "id",
        "revision",
        "digest"
      ],
      "additionalProperties": false
    },
    "predecessor": {
      "anyOf": [
        {
          "type": "null"
        },
        {
          "$ref": "urn:comuvia:schema:0.1:common#/$defs/reference"
        }
      ]
    },
    "probability": {
      "type": "number",
      "minimum": 0,
      "maximum": 1
    },
    "unit_interval": {
      "type": "number",
      "minimum": 0,
      "maximum": 1
    },
    "count": {
      "type": "integer",
      "minimum": 0
    },
    "language": {
      "type": "string",
      "pattern": "^[A-Za-z]{2,8}(-[A-Za-z0-9]{1,8})*$"
    },
    "media_type": {
      "type": "string",
      "pattern": "^[a-z0-9.+-]+/[A-Za-z0-9.+-]+( *;[ -~]*)?$"
    },
    "locator": {
      "description": "A locator recorded for provenance. The library never dereferences it; credentials are refused.",
      "type": "string",
      "pattern": "^[A-Za-z][A-Za-z0-9+.-]*:(?!//[^/]*@)[!-~]+$"
    },
    "legacy_id": {
      "type": "object",
      "properties": {
        "scheme": {
          "$ref": "urn:comuvia:schema:0.1:common#/$defs/code"
        },
        "value": {
          "$ref": "urn:comuvia:schema:0.1:common#/$defs/text"
        }
      },
      "required": [
        "scheme",
        "value"
      ],
      "additionalProperties": false
    },
    "legacy_ids": {
      "type": "array",
      "items": {
        "$ref": "urn:comuvia:schema:0.1:common#/$defs/legacy_id"
      }
    },
    "condition": {
      "type": "object",
      "properties": {
        "text": {
          "$ref": "urn:comuvia:schema:0.1:common#/$defs/text"
        },
        "state": {
          "type": "string",
          "enum": [
            "unresolved",
            "occurred",
            "not_occurred"
          ]
        },
        "note": {
          "$ref": "urn:comuvia:schema:0.1:common#/$defs/text"
        }
      },
      "required": [
        "text",
        "state"
      ],
      "additionalProperties": false
    },
    "codes": {
      "type": "array",
      "items": {
        "$ref": "urn:comuvia:schema:0.1:common#/$defs/code"
      },
      "uniqueItems": true
    },
    "limitations": {
      "description": "Known limitations of the record's source, as codes; [] means none known.",
      "$ref": "urn:comuvia:schema:0.1:common#/$defs/codes"
    },
    "vintage": {
      "type": "string",
      "enum": [
        "first_release",
        "latest_release"
      ]
    },
    "extensions": {
      "description": "Namespaced forward-compatible data. Hashed and preserved; never affects validation, eligibility or scoring.",
      "type": "object",
      "propertyNames": {
        "pattern": "^[a-z0-9-]+(\\.[a-z0-9-]+)+/v[0-9]+$",
        "x-comuvia-code": "invalid_extension_key"
      }
    }
  }
}
