{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://interchange.stellarview.net/schemas/ticket.schema.json",
  "title": "A help desk ticket, to and from the desk's adapter (Jira Service Management in the support example)",
  "allOf": [
    {
      "$ref": "common.schema.json#/$defs/provenance"
    }
  ],
  "type": "object",
  "required": [
    "kind",
    "ticket_id",
    "desk",
    "event_id",
    "event_type",
    "asset",
    "priority",
    "state",
    "source",
    "read_at",
    "validated_at"
  ],
  "unevaluatedProperties": false,
  "properties": {
    "kind": {
      "const": "ticket"
    },
    "ticket_id": {
      "$ref": "common.schema.json#/$defs/uuid"
    },
    "desk": {
      "type": "object",
      "required": [
        "adapter",
        "mode"
      ],
      "additionalProperties": false,
      "properties": {
        "adapter": {
          "type": "string"
        },
        "mode": {
          "enum": [
            "stub",
            "live",
            "fixture"
          ],
          "description": "stub: a local stand-in answered. fixture: the hub's fixture site answered in Atlassian's published shapes. Neither reached a real desk."
        },
        "base_url": {
          "type": "string"
        }
      }
    },
    "number": {
      "type": "string",
      "description": "The desk's key (SFBT-1). Absent while waiting to send."
    },
    "event_id": {
      "$ref": "common.schema.json#/$defs/uuid"
    },
    "event_type": {
      "$ref": "common.schema.json#/$defs/event_type_id"
    },
    "asset": {
      "$ref": "common.schema.json#/$defs/asset_ref"
    },
    "priority": {
      "type": "string"
    },
    "sla": {
      "type": "string"
    },
    "assignee": {
      "type": [
        "string",
        "null"
      ]
    },
    "state": {
      "enum": [
        "waiting_to_send",
        "open",
        "accepted",
        "in_progress",
        "waiting",
        "resolved",
        "closed",
        "unmapped"
      ],
      "description": "unmapped: the desk sent a status the mapping does not name. Shown with status_raw, never guessed."
    },
    "status_raw": {
      "type": "string"
    },
    "error": {
      "type": "string",
      "description": "The adapter's own error while waiting."
    },
    "history": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "state",
          "at"
        ],
        "additionalProperties": false,
        "properties": {
          "state": {
            "type": "string"
          },
          "status_raw": {
            "type": "string"
          },
          "at": {
            "$ref": "common.schema.json#/$defs/time"
          },
          "by": {
            "type": "string"
          }
        }
      }
    },
    "source": true,
    "read_at": true,
    "validated_at": true
  }
}