{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/depixapp-com/json-schema/depixapp-com-ticket-message-response-schema.json",
  "title": "TicketMessageResponse",
  "description": "The posted message plus the updated ticket.",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/depixapp-com-support-api-openapi.yml#/components/schemas/TicketMessageResponse",
  "type": "object",
  "required": [
    "message",
    "ticket"
  ],
  "additionalProperties": false,
  "properties": {
    "message": {
      "$ref": "#/$defs/TicketMessage"
    },
    "ticket": {
      "$ref": "#/$defs/Ticket"
    }
  },
  "$defs": {
    "Ticket": {
      "type": "object",
      "description": "A support ticket (summary view).",
      "required": [
        "id",
        "opener_type",
        "status",
        "subject",
        "category",
        "created_at",
        "last_activity_at",
        "closed_reason",
        "closed_at",
        "rating",
        "rated_at"
      ],
      "additionalProperties": false,
      "properties": {
        "id": {
          "type": "string",
          "description": "Ticket id (tkt_*)."
        },
        "opener_type": {
          "type": "string",
          "description": "Who opened the ticket, snapshotted from the account type at creation.",
          "enum": [
            "human",
            "agent"
          ]
        },
        "status": {
          "$ref": "#/$defs/TicketStatus"
        },
        "subject": {
          "type": "string",
          "description": "Ticket subject (4–120 chars)."
        },
        "category": {
          "type": "string",
          "description": "Ticket category.",
          "enum": [
            "bug",
            "question",
            "account",
            "payment",
            "other"
          ]
        },
        "created_at": {
          "type": "string",
          "description": "Creation timestamp (RFC 3339 UTC)."
        },
        "last_activity_at": {
          "type": "string",
          "description": "Timestamp of the last user/admin message (RFC 3339 UTC). System messages do not bump it."
        },
        "closed_reason": {
          "type": [
            "string",
            "null"
          ],
          "description": "Why the ticket closed: 'user', 'admin' or 'auto' — null while open."
        },
        "closed_at": {
          "type": [
            "string",
            "null"
          ],
          "description": "Close timestamp (RFC 3339 UTC) — null while open. Anchors the 7-day reopen window for auto-closed tickets."
        },
        "rating": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 0,
          "maximum": 10,
          "description": "Satisfaction score the ticket owner gave (0 = worst, 10 = best) — null until rated. Only a closed ticket can be rated, and only once."
        },
        "rated_at": {
          "type": [
            "string",
            "null"
          ],
          "description": "When the rating was submitted (RFC 3339 UTC) — null until rated."
        }
      }
    },
    "TicketAttachment": {
      "type": "object",
      "description": "Metadata of a file attached to a message. The bytes are forwarded to the support team (not stored or served back) — only the name and type are exposed.",
      "required": [
        "name",
        "mime"
      ],
      "additionalProperties": false,
      "properties": {
        "name": {
          "type": "string",
          "description": "Original filename (sanitized)."
        },
        "mime": {
          "type": [
            "string",
            "null"
          ],
          "description": "Content type (image/png, image/jpeg, image/webp, application/pdf, text/plain or application/json)."
        }
      }
    },
    "TicketMessage": {
      "type": "object",
      "description": "A single message in a ticket thread.",
      "required": [
        "id",
        "sender",
        "body",
        "created_at"
      ],
      "additionalProperties": false,
      "properties": {
        "id": {
          "type": "string",
          "description": "Message id."
        },
        "sender": {
          "type": "string",
          "description": "Who sent the message.",
          "enum": [
            "user",
            "admin",
            "system"
          ]
        },
        "body": {
          "type": "string",
          "description": "Message body."
        },
        "created_at": {
          "type": "string",
          "description": "Message timestamp (RFC 3339 UTC)."
        },
        "attachment": {
          "description": "Attached file metadata when the message carries a file, otherwise null. Present on every message (null for plain text).",
          "anyOf": [
            {
              "$ref": "#/$defs/TicketAttachment"
            },
            {
              "type": "null"
            }
          ]
        }
      }
    },
    "TicketStatus": {
      "type": "string",
      "description": "Ticket lifecycle status — the enum below is the complete, closed set. `closed` is terminal (an auto-closed ticket may be reopened by replying within 7 days). Terminal states (safe to stop polling): closed.",
      "enum": [
        "awaiting_reply",
        "answered",
        "closed"
      ],
      "oneOf": [
        {
          "const": "awaiting_reply",
          "description": "The ball is with support — a reply from support is pending. NEVER auto-closes."
        },
        {
          "const": "answered",
          "description": "Support replied; awaiting the user. Auto-closes after 2 business days of no user reply."
        },
        {
          "const": "closed",
          "description": "TERMINAL — closed by the user, support, or the 2-business-day auto-close sweep.",
          "x-terminal": true
        }
      ]
    }
  }
}