{
  "openapi": "3.1.0",
  "info": {
    "title": "Foresko Support API",
    "version": "0.1.0"
  },
  "servers": [
    { "url": "https://support.foresko.com" }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer"
      }
    }
  },
  "security": [{ "bearerAuth": [] }],
  "paths": {
    "/v1/health": {
      "get": {
        "security": [],
        "summary": "Health check",
        "responses": { "200": { "description": "OK" } }
      }
    },
    "/v1/chat-tokens": {
      "post": {
        "summary": "Create scoped short-lived chat token",
        "responses": { "201": { "description": "Chat token" } }
      }
    },
    "/v1/messages": {
      "post": {
        "summary": "Ingest user message and enqueue AI reply. Accepts admin token or scoped chat token.",
        "responses": {
          "202": { "description": "Ticket, user message and queued AI reply job" },
          "201": { "description": "Duplicate request or already available reply" }
        }
      }
    },
    "/v1/chat/history": {
      "get": {
        "summary": "Get current open chat ticket and messages. Accepts admin token or scoped chat token.",
        "responses": { "200": { "description": "Ticket and messages" } }
      }
    },
    "/v1/jobs/{job_id}": {
      "get": {
        "summary": "Get async AI reply job status",
        "responses": { "200": { "description": "AI reply job" } }
      }
    },
    "/v1/apps/{app_id}": {
      "get": { "summary": "Get app profile", "responses": { "200": { "description": "App profile" } } },
      "put": { "summary": "Create or update app profile", "responses": { "200": { "description": "App profile" } } }
    },
    "/v1/apps/{app_id}/knowledge": {
      "get": { "summary": "Search app knowledge", "responses": { "200": { "description": "Knowledge hits" } } },
      "post": { "summary": "Add app knowledge document", "responses": { "201": { "description": "Knowledge document" } } }
    },
    "/v1/tickets": {
      "get": { "summary": "List tickets", "responses": { "200": { "description": "Tickets" } } }
    },
    "/v1/tickets/{ticket_id}": {
      "get": { "summary": "Get ticket with messages", "responses": { "200": { "description": "Ticket and messages" } } }
    },
    "/v1/tickets/{ticket_id}/close": {
      "post": { "summary": "Close ticket", "responses": { "200": { "description": "Closed ticket" } } }
    },
    "/v1/tickets/{ticket_id}/handoff": {
      "post": { "summary": "Mark ticket as requiring human operator", "responses": { "200": { "description": "Ticket marked for handoff" } } }
    },
    "/v1/tickets/{ticket_id}/operator-advice": {
      "post": { "summary": "Save operator advice and let AI send the final user reply", "responses": { "200": { "description": "Advice message and assistant reply" } } }
    },
    "/v1/search": {
      "get": { "summary": "Full-text message search", "responses": { "200": { "description": "Messages" } } }
    }
  }
}