{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://fullsend.ai/normative/entity-context-snapshot/v1/reviews.schema.json",
  "title": "ReviewRelationships",
  "type": "object",
  "required": ["reviews", "threads"],
  "properties": {
    "reviews": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["id", "record_key", "state", "submitted_at"],
        "properties": {
          "id": { "$ref": "common.schema.json#/$defs/structural_id" },
          "record_key": { "$ref": "common.schema.json#/$defs/record_key" },
          "state": { "enum": ["approved", "changes_requested", "commented", "dismissed"] },
          "reviewed_sha": { "$ref": "common.schema.json#/$defs/git_oid" },
          "submitted_at": { "$ref": "common.schema.json#/$defs/timestamp" },
          "dismissed_at": {
            "oneOf": [
              { "$ref": "common.schema.json#/$defs/timestamp" },
              { "type": "null" }
            ]
          },
          "dismissed_by_actor_id": {
            "oneOf": [
              { "$ref": "common.schema.json#/$defs/structural_id" },
              { "type": "null" }
            ]
          }
        },
        "allOf": [
          {
            "if": { "properties": { "state": { "const": "dismissed" } }, "required": ["state"] },
            "then": { "required": ["dismissed_at", "dismissed_by_actor_id"] },
            "else": { "not": { "anyOf": [{ "required": ["dismissed_at"] }, { "required": ["dismissed_by_actor_id"] }] } }
          }
        ],
        "additionalProperties": false
      }
    },
    "threads": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["id", "thread_key", "created_at", "order_path", "record_keys", "replies"],
        "properties": {
          "id": { "$ref": "common.schema.json#/$defs/structural_id" },
          "thread_key": { "$ref": "common.schema.json#/$defs/record_key" },
          "created_at": { "$ref": "common.schema.json#/$defs/timestamp" },
          "order_path": { "type": "string", "pattern": "^threads/[0-9a-f]{64}[.]order$" },
          "record_keys": {
            "type": "array",
            "items": { "$ref": "common.schema.json#/$defs/record_key" },
            "uniqueItems": true
          },
          "replies": {
            "type": "array",
            "items": {
              "type": "object",
              "required": ["record_key", "parent_record_key"],
              "properties": {
                "record_key": { "$ref": "common.schema.json#/$defs/record_key" },
                "parent_record_key": { "$ref": "common.schema.json#/$defs/record_key" }
              },
              "additionalProperties": false
            }
          },
          "review_id": { "$ref": "common.schema.json#/$defs/structural_id" },
          "review_record_key": { "$ref": "common.schema.json#/$defs/record_key" },
          "reviewed_sha": { "$ref": "common.schema.json#/$defs/git_oid" },
          "path": { "$ref": "common.schema.json#/$defs/repository_path" },
          "line": { "type": "integer", "minimum": 1 },
          "side": { "enum": ["left", "right"] },
          "start_line": { "type": "integer", "minimum": 1 },
          "original_line": { "type": "integer", "minimum": 1 },
          "original_start_line": { "type": "integer", "minimum": 1 },
          "original_side": { "enum": ["left", "right"] }
        },
        "additionalProperties": false
      }
    }
  },
  "additionalProperties": false
}
