{
  "openapi": "3.1.0",
  "info": {
    "title": "DueChat Helpdesk Workspace API",
    "version": "2.0.0",
    "description": "Authenticated REST routes for the DueChat helpdesk workspace. Use a DueChat session Bearer token (Supabase access token from the web app). Public widget routes use the workspace public_key query param instead. Paths match server/routes/support.ts as of this release."
  },
  "servers": [
    {
      "url": "https://duechat.io",
      "description": "Production API host"
    }
  ],
  "security": [{ "DueChatSession": [] }],
  "components": {
    "securitySchemes": {
      "DueChatSession": {
        "type": "http",
        "scheme": "bearer",
        "description": "Supabase access token from a DueChat login session"
      }
    }
  },
  "paths": {
    "/api/support/workspace": {
      "get": {
        "operationId": "getSupportWorkspace",
        "summary": "Workspace, usage, and plan features"
      },
      "patch": {
        "operationId": "patchSupportWorkspace",
        "summary": "Update workspace name, tone, handoff timing, refund rules"
      }
    },
    "/api/support/stores/{platform}": {
      "put": {
        "operationId": "upsertSupportStore",
        "summary": "Connect or update Shopify or WooCommerce credentials",
        "parameters": [
          {
            "name": "platform",
            "in": "path",
            "required": true,
            "schema": { "type": "string", "enum": ["shopify", "woocommerce"] }
          }
        ]
      }
    },
    "/api/support/channels": {
      "get": {
        "operationId": "listSupportChannels",
        "summary": "List email, widget, and social channels"
      }
    },
    "/api/support/conversations": {
      "get": {
        "operationId": "listSupportConversations",
        "summary": "Recent inbox conversations"
      }
    },
    "/api/support/conversations/{id}/messages": {
      "get": {
        "operationId": "listConversationMessages",
        "summary": "Messages for one conversation"
      }
    },
    "/api/support/conversations/{id}/ticket-type": {
      "patch": {
        "operationId": "setConversationTicketType",
        "summary": "Manually set ticket type on a conversation"
      }
    },
    "/api/support/ticket-types": {
      "get": {
        "operationId": "listTicketTypes",
        "summary": "Ticket types and modes (copilot, autopilot, blocked)"
      },
      "post": {
        "operationId": "createTicketType",
        "summary": "Create a custom ticket type"
      }
    },
    "/api/support/ticket-types/edit-rates": {
      "get": {
        "operationId": "getTicketTypeEditRates",
        "summary": "Edit rate per ticket type for the last 7 or 30 days",
        "parameters": [
          {
            "name": "days",
            "in": "query",
            "schema": { "type": "integer", "enum": [7, 30] }
          }
        ]
      }
    },
    "/api/support/ticket-types/{id}": {
      "patch": {
        "operationId": "patchTicketType",
        "summary": "Change label, mode, enabled, or sort order"
      }
    },
    "/api/support/ticket-types/seed": {
      "post": {
        "operationId": "seedDefaultTicketTypes",
        "summary": "Seed default tracking, returns, and refund types"
      }
    },
    "/api/support/drafts": {
      "get": {
        "operationId": "listPendingDrafts",
        "summary": "Copilot drafts awaiting review",
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "schema": { "type": "string", "enum": ["pending", "all"] }
          }
        ]
      }
    },
    "/api/support/drafts/{id}/send": {
      "post": {
        "operationId": "sendDraftAsIs",
        "summary": "Approve and send a Copilot draft unchanged"
      }
    },
    "/api/support/drafts/{id}/send-edited": {
      "post": {
        "operationId": "sendDraftEdited",
        "summary": "Send after editing draft body"
      }
    },
    "/api/support/drafts/{id}/discard": {
      "post": {
        "operationId": "discardDraft",
        "summary": "Discard a pending draft"
      }
    },
    "/api/support/public/session": {
      "post": {
        "operationId": "createWidgetSession",
        "summary": "Start widget session (public_key in body, widget User-Agent required)",
        "security": []
      }
    },
    "/api/support/public/messages": {
      "post": {
        "operationId": "postWidgetMessage",
        "summary": "Customer message via widget (returns assistant draft or reply)",
        "security": []
      }
    }
  }
}