{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:hayat:schema:message:vNEXT-D",
  "title": "HAYAT message \u2014 vNEXT-D draft",
  "type": "object",
  "properties": {
    "protocol_version": {
      "const": "vNEXT-D"
    },
    "project_id": {
      "type": "string",
      "format": "uuid"
    },
    "artifact_id": {
      "type": "string",
      "format": "uuid"
    },
    "record_type": {
      "const": "message"
    },
    "author_id": {
      "type": "string",
      "format": "uuid"
    },
    "created_at": {
      "type": "string",
      "format": "date-time",
      "pattern": "Z$"
    },
    "visibility": {
      "enum": [
        "local-example",
        "public",
        "shared",
        "private"
      ]
    },
    "source_refs": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "artifact_id": {
            "type": "string",
            "format": "uuid"
          },
          "sha256": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "location": {
            "type": "string",
            "minLength": 1,
            "pattern": "^(?!/)(?!.*(?:\\.\\.|:)).+$"
          }
        },
        "required": [
          "artifact_id",
          "sha256"
        ],
        "additionalProperties": false
      },
      "minItems": 0,
      "uniqueItems": true
    },
    "content_sha256": {
      "type": "string",
      "pattern": "^[a-f0-9]{64}$"
    },
    "payload_location": {
      "type": "string",
      "minLength": 1
    },
    "provenance_limitation": {
      "type": "string"
    },
    "simulation": {
      "type": "boolean"
    },
    "message_id": {
      "type": "string",
      "format": "uuid"
    },
    "action_id": {
      "type": "string",
      "format": "uuid"
    },
    "sender_id": {
      "type": "string",
      "format": "uuid"
    },
    "recipient_ids": {
      "type": "array",
      "items": {
        "type": "string",
        "format": "uuid"
      },
      "minItems": 1,
      "uniqueItems": true
    },
    "in_reply_to": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "artifact_id": {
              "type": "string",
              "format": "uuid"
            },
            "sha256": {
              "type": "string",
              "pattern": "^[a-f0-9]{64}$"
            },
            "location": {
              "type": "string",
              "minLength": 1,
              "pattern": "^(?!/)(?!.*(?:\\.\\.|:)).+$"
            }
          },
          "required": [
            "artifact_id",
            "sha256"
          ],
          "additionalProperties": false
        },
        {
          "type": "null"
        }
      ]
    },
    "approval_ref": {
      "type": "object",
      "properties": {
        "artifact_id": {
          "type": "string",
          "format": "uuid"
        },
        "sha256": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$"
        },
        "location": {
          "type": "string",
          "minLength": 1,
          "pattern": "^(?!/)(?!.*(?:\\.\\.|:)).+$"
        }
      },
      "required": [
        "artifact_id",
        "sha256"
      ],
      "additionalProperties": false
    }
  },
  "required": [
    "protocol_version",
    "project_id",
    "artifact_id",
    "record_type",
    "author_id",
    "created_at",
    "visibility",
    "source_refs",
    "content_sha256",
    "payload_location",
    "provenance_limitation",
    "simulation",
    "message_id",
    "action_id",
    "sender_id",
    "recipient_ids",
    "in_reply_to",
    "approval_ref"
  ],
  "additionalProperties": false,
  "allOf": [
    {
      "if": {
        "properties": {
          "source_refs": {
            "maxItems": 0
          }
        }
      },
      "then": {
        "properties": {
          "provenance_limitation": {
            "type": "string",
            "minLength": 1
          }
        }
      }
    }
  ]
}
