{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://openssom.org/schema/asset-class-template.json",
  "title": "SSOM Asset Class Template",
  "description": "DRAFT (RFC-0004). For one Asset Class, the Signals an Asset of the class is expected to have, the quantity kind and unit each is compared in, and the Relationships it is expected to have. A template states an expectation. An Asset is never invalid for lacking an expected Signal; the gap is reported.",
  "type": "object",
  "required": [
    "template_id",
    "ssom_version",
    "asset_class_ref",
    "template_version",
    "template_status",
    "expected_signals",
    "provenance"
  ],
  "properties": {
    "template_id": {
      "type": "string",
      "pattern": "^urn:ssom:class-template:"
    },
    "ssom_version": {
      "type": "string"
    },
    "asset_class_ref": {
      "type": "string",
      "pattern": "^urn:ssom:asset-class:"
    },
    "template_version": {
      "type": "string"
    },
    "template_status": {
      "enum": [
        "proposed",
        "accepted",
        "deprecated"
      ],
      "description": "A template is proposed until a named person or team accepts it, as a vocabulary term is in RFC-0003 C10."
    },
    "expected_signals": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "required": [
          "metric",
          "expectation",
          "value_kind"
        ],
        "properties": {
          "metric": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]*$"
          },
          "expectation": {
            "enum": [
              "expected",
              "optional"
            ],
            "description": "`expected`: an Asset of the class normally has the Signal, and its absence is reported as a gap. `optional`: the Signal is named so that those who have it use one name and one unit."
          },
          "value_kind": {
            "$ref": "common.json#/$defs/signalValueKind"
          },
          "signal_role": {
            "$ref": "common.json#/$defs/signalRole"
          },
          "quantity_kind": {
            "$ref": "common.json#/$defs/quantityKind"
          },
          "unit": {
            "$ref": "common.json#/$defs/unitReference",
            "description": "The unit in which values of this Signal are compared across Assets of the class."
          }
        },
        "allOf": [
          {
            "if": {
              "required": [
                "quantity_kind"
              ]
            },
            "then": {
              "required": [
                "unit"
              ]
            }
          },
          {
            "if": {
              "required": [
                "unit"
              ]
            },
            "then": {
              "required": [
                "quantity_kind"
              ]
            }
          },
          {
            "if": {
              "properties": {
                "value_kind": {
                  "const": "state"
                }
              }
            },
            "then": {
              "not": {
                "required": [
                  "quantity_kind"
                ]
              }
            },
            "else": {
              "required": [
                "quantity_kind"
              ]
            }
          }
        ],
        "additionalProperties": false
      }
    },
    "expected_relationships": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "relationship_type",
          "template_class_end",
          "other_class_ref",
          "expectation"
        ],
        "properties": {
          "relationship_type": {
            "$ref": "common.json#/$defs/coreRelationshipTerm"
          },
          "template_class_end": {
            "enum": [
              "from",
              "to"
            ],
            "description": "Which end of the Relationship an Asset of the template's class is."
          },
          "other_class_ref": {
            "type": "string",
            "pattern": "^urn:ssom:asset-class:"
          },
          "expectation": {
            "enum": [
              "expected",
              "optional"
            ]
          }
        },
        "additionalProperties": false
      }
    },
    "state_lineage": {
      "$ref": "common.json#/$defs/stateLineage"
    },
    "provenance": {
      "$ref": "common.json#/$defs/provenance"
    },
    "extensions": {
      "type": "object",
      "additionalProperties": true
    }
  },
  "additionalProperties": true
}
