{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Clarivern intelligence, risk and control links",
  "type": "object",
  "properties": {
    "riskId": {
      "type": "string",
      "minLength": 1
    },
    "riskEvent": {
      "type": "string",
      "minLength": 1
    },
    "categories": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      },
      "uniqueItems": true,
      "minItems": 1
    },
    "causes": {
      "type": "array",
      "items": {
        "allOf": [
          {
            "type": "object",
            "properties": {
              "text": {
                "type": "string",
                "minLength": 1
              },
              "status": {
                "enum": [
                  "confirmed",
                  "reported",
                  "hypothesis",
                  "unknown"
                ]
              },
              "evidenceRefs": {
                "type": "array",
                "items": {
                  "type": "string",
                  "minLength": 1
                },
                "uniqueItems": true
              }
            },
            "required": [
              "text",
              "status",
              "evidenceRefs"
            ]
          },
          {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "minLength": 1
              }
            },
            "required": [
              "id"
            ]
          }
        ]
      },
      "minItems": 1
    },
    "impacts": {
      "type": "array",
      "items": {
        "allOf": [
          {
            "type": "object",
            "properties": {
              "text": {
                "type": "string",
                "minLength": 1
              },
              "status": {
                "enum": [
                  "confirmed",
                  "reported",
                  "hypothesis",
                  "unknown"
                ]
              },
              "evidenceRefs": {
                "type": "array",
                "items": {
                  "type": "string",
                  "minLength": 1
                },
                "uniqueItems": true
              }
            },
            "required": [
              "text",
              "status",
              "evidenceRefs"
            ]
          },
          {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "minLength": 1
              }
            },
            "required": [
              "id"
            ]
          }
        ]
      },
      "minItems": 1
    },
    "eventIds": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      },
      "uniqueItems": true
    },
    "knowledgeRefs": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      },
      "uniqueItems": true
    },
    "controlLinks": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "controlId": {
            "type": "string",
            "minLength": 1
          },
          "objectiveId": {
            "type": "string",
            "minLength": 1
          },
          "objective": {
            "type": "string",
            "minLength": 1
          },
          "activityIds": {
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 1
            },
            "uniqueItems": true
          }
        },
        "required": [
          "controlId",
          "objectiveId",
          "objective",
          "activityIds"
        ]
      }
    },
    "metrics": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1
          },
          "subjectType": {
            "enum": [
              "intelligence",
              "knowledge",
              "cause",
              "risk",
              "impact",
              "control",
              "objective",
              "activity"
            ]
          },
          "subjectId": {
            "type": "string",
            "minLength": 1
          },
          "definition": {
            "type": "string",
            "minLength": 1
          },
          "unit": {
            "type": "string",
            "minLength": 1
          },
          "dataSource": {
            "type": "string",
            "minLength": 1
          },
          "owner": {
            "type": "string",
            "minLength": 1
          },
          "target": {
            "type": "string",
            "minLength": 1
          },
          "period": {
            "type": "string",
            "minLength": 1
          },
          "value": {
            "type": [
              "number",
              "null"
            ]
          },
          "evidenceRefs": {
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 1
            },
            "uniqueItems": true
          }
        },
        "required": [
          "id",
          "subjectType",
          "subjectId",
          "definition",
          "unit",
          "dataSource",
          "owner"
        ]
      }
    }
  },
  "required": [
    "riskId",
    "riskEvent",
    "categories",
    "causes",
    "impacts",
    "eventIds",
    "knowledgeRefs",
    "controlLinks",
    "metrics"
  ]
}
