openapi: "3.0.3"
info:
  title: "Support tickets API"
  version: "1.0.0"
  description: "A ticket message with an empty body is rejected by the check constraint, and this is one of the most common seed failures. Priority and state are independent enums, and a ticket can be urgent and closed at the same time. The message author enum includes system, because automated replies are stored in the same table. Tickets reference contacts, so the contact row has to exist before any ticket is inserted."
paths: {}
x-domain-id: "support"
x-dialect: "postgres"
components:
  schemas:
    contacts:
      type: "object"
      x-primary-key: "id"
      required: ["id", "email", "created_at"]
      properties:
        id:
          type: "string"
          format: "uuid"
        email:
          type: "string"
          format: "email"
          x-unique: true
        created_at:
          type: "string"
          format: "date-time"
    tickets:
      type: "object"
      x-primary-key: "id"
      required: ["id", "contact_id", "subject", "priority", "state", "opened_at"]
      properties:
        id:
          type: "string"
          format: "uuid"
        contact_id:
          $ref: "#/components/schemas/contacts"
        subject:
          type: "string"
        priority:
          type: "string"
          enum: ["low", "normal", "high", "urgent"]
        state:
          type: "string"
          enum: ["open", "pending", "closed"]
        opened_at:
          type: "string"
          format: "date-time"
    ticket_messages:
      type: "object"
      x-primary-key: "id"
      required: ["id", "ticket_id", "author", "body", "sent_at"]
      properties:
        id:
          type: "string"
          format: "uuid"
        ticket_id:
          $ref: "#/components/schemas/tickets"
        author:
          type: "string"
          enum: ["customer", "agent", "system"]
        body:
          type: "string"
          minLength: 1
        sent_at:
          type: "string"
          format: "date-time"
