{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:hayat:schema:conflict:vNEXT-D",
  "title": "HAYAT conflict \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": "conflict"
    },
    "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"
    },
    "conflict_id": {
      "type": "string",
      "format": "uuid"
    },
    "base_version": {
      "type": "string",
      "format": "uuid"
    },
    "competing_artifact_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": 2,
      "uniqueItems": true
    },
    "detected_at": {
      "type": "string",
      "format": "date-time",
      "pattern": "Z$"
    },
    "resolver_id": {
      "anyOf": [
        {
          "type": "string",
          "format": "uuid"
        },
        {
          "type": "null"
        }
      ]
    },
    "resolution_state": {
      "enum": [
        "unassigned",
        "pending",
        "resolved"
      ]
    },
    "resolution_ref": {
      "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"
        }
      ]
    }
  },
  "required": [
    "protocol_version",
    "project_id",
    "artifact_id",
    "record_type",
    "author_id",
    "created_at",
    "visibility",
    "source_refs",
    "content_sha256",
    "payload_location",
    "provenance_limitation",
    "simulation",
    "conflict_id",
    "base_version",
    "competing_artifact_refs",
    "detected_at",
    "resolver_id",
    "resolution_state",
    "resolution_ref"
  ],
  "additionalProperties": false,
  "allOf": [
    {
      "if": {
        "properties": {
          "source_refs": {
            "maxItems": 0
          }
        }
      },
      "then": {
        "properties": {
          "provenance_limitation": {
            "type": "string",
            "minLength": 1
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "resolution_state": {
            "const": "resolved"
          }
        }
      },
      "then": {
        "properties": {
          "resolver_id": {
            "type": "string",
            "format": "uuid"
          },
          "resolution_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
          }
        }
      }
    }
  ]
}
