{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://zenith-research.ca/ontology/normalized/v0.1.0/schemas/request.schema.json",
  "title": "Zenith Request profiles",
  "$defs": {
    "SOPContent": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "format": "uri",
          "pattern": "^[A-Za-z][A-Za-z0-9+.-]*:"
        },
        "version": {
          "type": "string",
          "minLength": 1
        },
        "applicability": {
          "type": "array",
          "items": {
            "type": "string",
            "format": "uri",
            "pattern": "^[A-Za-z][A-Za-z0-9+.-]*:"
          },
          "minItems": 1
        },
        "inputSchema": {
          "type": [
            "object",
            "boolean"
          ]
        },
        "rules": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "minItems": 1
        },
        "actions": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "operation": {
                "type": "string",
                "format": "uri",
                "pattern": "^[A-Za-z][A-Za-z0-9+.-]*:"
              },
              "meaning": {
                "type": "string",
                "minLength": 1
              }
            },
            "required": [
              "operation",
              "meaning"
            ],
            "additionalProperties": false
          }
        },
        "outcomes": {
          "type": [
            "object",
            "boolean"
          ]
        },
        "schemaDialect": {
          "const": "https://json-schema.org/draft/2020-12/schema"
        }
      },
      "required": [
        "id",
        "version",
        "applicability",
        "inputSchema",
        "rules",
        "actions",
        "outcomes",
        "schemaDialect"
      ],
      "additionalProperties": false
    },
    "ReceiveRequestInput": {
      "type": "object",
      "properties": {
        "request": {
          "$ref": "https://zenith-research.ca/ontology/normalized/v0.1.0/schemas/core.schema.json#/$defs/ArtifactRef"
        }
      },
      "required": [
        "request"
      ],
      "additionalProperties": false
    },
    "ReceiveRequestOutput": {
      "type": "object",
      "properties": {
        "requestId": {
          "type": "string",
          "format": "uri",
          "pattern": "^[A-Za-z][A-Za-z0-9+.-]*:"
        },
        "retainedRequest": {
          "$ref": "https://zenith-research.ca/ontology/normalized/v0.1.0/schemas/core.schema.json#/$defs/ArtifactRef"
        },
        "registration": {
          "enum": [
            "registered",
            "already_registered"
          ]
        }
      },
      "required": [
        "requestId",
        "retainedRequest",
        "registration"
      ],
      "additionalProperties": false
    },
    "ReceiveRequestError": {
      "type": "object",
      "properties": {
        "code": {
          "enum": [
            "invalid_request",
            "sop_unavailable",
            "sop_not_applicable",
            "request_content_conflict",
            "artifact_subject_unverified"
          ]
        }
      },
      "required": [
        "code"
      ],
      "additionalProperties": false
    },
    "RequestCore": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "format": "uri",
          "pattern": "^[A-Za-z][A-Za-z0-9+.-]*:"
        },
        "type": {
          "type": "string",
          "format": "uri",
          "pattern": "^[A-Za-z][A-Za-z0-9+.-]*:"
        },
        "label": {
          "type": "string",
          "minLength": 1
        },
        "requestedOutcome": {
          "type": "string",
          "minLength": 1
        },
        "requester": {
          "type": "string",
          "format": "uri",
          "pattern": "^[A-Za-z][A-Za-z0-9+.-]*:"
        },
        "recipient": {
          "type": "string",
          "format": "uri",
          "pattern": "^[A-Za-z][A-Za-z0-9+.-]*:"
        },
        "applicableSOP": {
          "$ref": "https://zenith-research.ca/ontology/normalized/v0.1.0/schemas/core.schema.json#/$defs/ArtifactRef"
        },
        "supportingArtifacts": {
          "type": "array",
          "items": {
            "$ref": "https://zenith-research.ca/ontology/normalized/v0.1.0/schemas/core.schema.json#/$defs/ArtifactRef"
          }
        }
      },
      "required": [
        "id",
        "type"
      ]
    },
    "RequestSubmission": {
      "allOf": [
        {
          "$ref": "#/$defs/RequestCore"
        },
        {
          "required": [
            "requestedOutcome",
            "requester",
            "recipient"
          ]
        }
      ]
    },
    "GeneralRequest": {
      "allOf": [
        {
          "$ref": "#/$defs/RequestSubmission"
        },
        {
          "properties": {
            "type": {
              "const": "https://zenith-research.ca/ontology/terms/Request"
            }
          }
        }
      ],
      "unevaluatedProperties": false
    },
    "HandlingRecord": {
      "type": "object",
      "properties": {
        "receiver": {
          "type": "string",
          "format": "uri",
          "pattern": "^[A-Za-z][A-Za-z0-9+.-]*:"
        },
        "request": {
          "$ref": "https://zenith-research.ca/ontology/normalized/v0.1.0/schemas/core.schema.json#/$defs/ArtifactRef"
        },
        "selectedSOP": {
          "$ref": "https://zenith-research.ca/ontology/normalized/v0.1.0/schemas/core.schema.json#/$defs/ArtifactRef"
        },
        "selectionPolicy": {
          "$ref": "https://zenith-research.ca/ontology/normalized/v0.1.0/schemas/core.schema.json#/$defs/ArtifactRef"
        },
        "evidence": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "https://zenith-research.ca/ontology/normalized/v0.1.0/schemas/core.schema.json#/$defs/ArtifactRef"
          }
        },
        "recordRevision": {
          "type": "integer",
          "minimum": 1
        },
        "progress": {
          "type": "object",
          "properties": {
            "state": {
              "type": "string",
              "minLength": 1
            },
            "observedAt": {
              "type": "string",
              "format": "date-time"
            }
          },
          "required": [
            "state",
            "observedAt"
          ],
          "additionalProperties": false
        }
      },
      "required": [
        "receiver",
        "request",
        "selectedSOP",
        "selectionPolicy",
        "evidence",
        "recordRevision",
        "progress"
      ],
      "additionalProperties": false
    }
  }
}
