openapi: 3.0.0
info:
  title: IPXON Customer Panel
  description: An API for IPXON Customer Panel
  version: 1.0.0

# All endpoints are authenticated with the API key sent in the `X-API-Key`
# header (see components.securitySchemes.ApiKeyAuth). Session-bootstrap endpoints
# override this with `security: []`; the API-key management endpoints
# (/v1/auth/apikeys*) override it with the SessionCookie scheme, since a key cannot
# be managed with another API key — they require the logged-in session.
security:
  - ApiKeyAuth: []

components:
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-API-Key
      description: >-
        API key authentication. Send the key issued by
        `POST /v1/auth/apikeys` in the `X-API-Key` request header
        (e.g. `X-API-Key: cpk_live_2cabe9a...`). API clients add this header on
        every request; the gateway validates it via `GET /v1/auth/` and forwards
        the request to the target service. Browser clients may authenticate with
        the session cookie instead.
    SessionCookie:
      type: apiKey
      in: cookie
      name: mysession
      description: >-
        Browser session cookie set by `POST /v1/auth/login`. The API-key
        management endpoints (`/v1/auth/apikeys*`) require it: a key cannot be
        managed with another API key, so they are protected by the logged-in
        session (the auth service validates it, returning 401 without a valid
        session).
  schemas:
    profile:
      type: object
      properties:
        id:
          type: number
        name:
          type: string
        lastname:
          type: string
        company:
          type: string
        country:
          type: string
        owner:
          type: boolean
          description: present in the default (non-permission) profiles shape
        authorized:
          type: boolean
          description: present only in the authorized-profiles shape (permission param sent)
      examples:
        Profiles:
          value:
            - id: 1
              name: John
              lastname: Doe
              company: IPXON
              country: UY
        AuthorizedProfiles:
          value:
            - id: 1
              name: John
              lastname: Doe
              authorized: true
    vps:
      type: object
      properties:
        id:
          type: number
        name:
          type: string
        pid:
          type: number
        iata:
          type: string
        location:
          type: string
        status:
          type: string
          description: (running, stopped, paused, unknown)
        resources:
          type: object
          properties:
            bandwidth:
              type: string
            cpu:
              type: string
            ram:
              type: string
            storage:
              type: string
            transfer:
              type: string
        settings:
          type: object
          properties:
            additionalIp:
              type: string
            controlPanel:
              type: string
            hostname:
              type: string
            operativeSystem:
              type: string
            primaryIp:
              type: string
        billing:
          type: object
          properties:
            status:
              type: string
              description: (Active, Pending, Suspended, Cancelled, Fraud)
            value:
              type: string
            date:
              type: string
            nextDueDate:
              type: string
            paymentMethod:
              type: string
            cycle:
              type: string
      examples:
        VirtualMachine:
          value:
            - id: 1
              name: "Cloud Server M2 [SCL]"
              pid: 2
              iata: "scl"
              location: "Santiago de Chile"
              resources:
                bandwidth: "100 Mbps"
                cpu: "1 vCPU"
                ram: "1 GB"
                storage: "10 GB / SSD"
                transfer: "1 TB"
              settings:
                additionalIp: 1
                controlPanel: "CPanel"
                hostname: "test.hostname.com"
                operativeSystem: "Centos8"
                primaryIp: "0.0.0.0"
              billing:
                status: "Active"
                value: "114.00"
                date: "2020-10-02"
                nextDueDate: "2021-04-06"
                paymentMethod: "PayPal Basic"
                cycle: "Monthly"
    paymethod:
      type: object
      properties:
        module:
          type: string
        name:
          type: string
      examples:
        Paymethods:
          value:
            - module: "paypal"
              name: "Paypal"
    currency:
      type: object
      properties:
        code:
          type: string
          example: USD
        symbol:
          type: string
          example: "$"
        format:
          type: string
    order:
      type: object
      description: Order payload for `POST /v1/billing/`.
      properties:
        profileId:
          type: integer
          example: 1
        currency:
          type: string
          example: usd
        cycle:
          type: string
          enum: [monthly, quarterly, semiannually, annually]
          example: monthly
          description: Billing cycle; passed straight to WHMCS AddOrder `billingcycle[]`.
        PaymentMethod:
          type: string
          example: stripe
          description: WHMCS gateway system name (module); passed to WHMCS AddOrder `paymentmethod`.
        hostname:
          type: string
          example: my-server
        count:
          type: integer
          example: 1
        resources:
          type: array
          items:
            type: string
        addons:
          type: array
          items:
            type: string
        plans:
          type: array
          items:
            type: string
        bgps:
          type: array
          items:
            type: string
        ultraproxies:
          type: array
          items:
            type: string
    orderResponse:
      type: object
      properties:
        invoiceId:
          type: integer
          example: 1001
        discount:
          type: string
          example: "0.00"
        total:
          type: string
          example: "120.00"
        currency:
          $ref: "#/components/schemas/currency"
    billing:
      type: object
      properties:
        cycle:
          type: string
          example: Monthly
        date:
          type: string
          example: "2020-10-02"
        nextDueDate:
          type: string
          example: "2021-04-06"
        paymentMethod:
          type: string
          example: paypal
        paymentMethodName:
          type: string
          example: PayPal Basic
        status:
          type: string
          description: (Active, Pending, Suspended, Cancelled, Fraud)
          example: Active
        value:
          type: string
          example: "114.00"
        currency:
          $ref: "#/components/schemas/currency"
        pendings:
          type: integer
          example: 0
        hasCancellationRequest:
          type: boolean
          example: false
    service:
      type: object
      description: Full service detail as returned by the single-service endpoint.
      properties:
        id:
          type: integer
        name:
          type: string
        pid:
          type: integer
        iata:
          type: string
        location:
          type: string
        resources:
          type: object
          additionalProperties:
            type: string
          description: Dynamic key/value map (bandwidth, cpu, ram, storage, transfer, ...)
        settings:
          type: object
          additionalProperties:
            type: string
          description: Dynamic key/value map (hostname, primaryIp, operativeSystem, ...)
        billing:
          $ref: "#/components/schemas/billing"
        credentials:
          type: object
          additionalProperties:
            type: string
        operativeSystem:
          type: object
          additionalProperties:
            type: string
        additionalIp:
          type: object
          additionalProperties:
            type: array
            items:
              type: string
        bgp:
          type: boolean
        status:
          type: string
          description: (running, stopped, paused, unknown)
        type:
          type: string
          description: Service type (vps, baremetal, colocation)
        externalId:
          type: string
        installing:
          type: boolean
          description: True while an OS install/reinstall is in progress
        osInstalledAt:
          type: string
          format: date-time
        createdAt:
          type: string
        powerState:
          type: string
          description: "Baremetal power state: running, stopped, ..."
        prefixes:
          type: array
          items:
            type: string
          description: Routed IP prefixes (CIDR) for baremetal; empty when none
        hardware:
          type: object
          description: Baremetal hardware inventory
          properties:
            manufacturer:
              type: string
            motherboard:
              type: string
            boardId:
              type: string
            bios:
              type: string
            bmcFirmware:
              type: string
            cpu:
              type: string
            memoryBytes:
              type: integer
              description: Installed memory in bytes
            licenses:
              type: array
              items:
                type: string
        bmc:
          type: object
          description: Baremetal BMC info
          properties:
            vendor:
              type: string
            mode:
              type: string
              description: BMC network mode (e.g. shared, dedicated)
            firmwareVersion:
              type: string
        sync:
          type: object
          description: Baremetal hardware sync/report timestamps
          properties:
            lastHardwareSyncAt:
              type: string
              format: date-time
            lastHardwareReportAt:
              type: string
              format: date-time
            lastHardwareReportSource:
              type: string
            updatedAt:
              type: string
              format: date-time
    servicePartial:
      type: object
      description: Reduced service shape used in the paginated services list.
      properties:
        id:
          type: integer
        name:
          type: string
        pid:
          type: integer
        iata:
          type: string
        location:
          type: string
        settings:
          type: object
          additionalProperties:
            type: string
        billing:
          $ref: "#/components/schemas/billing"
        status:
          type: string
        type:
          type: string
        externalId:
          type: string
        transferCapacity:
          type: number
          description: Transfer allowance in bytes
        transferUsageBytes:
          type: number
          description: Transfer used in the current period, in bytes
        installing:
          type: boolean
          description: True while an OS install/reinstall is in progress
    dedicatedStatusResponse:
      type: object
      description: >-
        Reply of a successful dedicated power action (start, shutdown, reboot).
        Failures come back with a non-200 status and an `error` body.
      properties:
        service_id:
          type: string
          example: "9233"
        device_id:
          type: string
          description: deprecated, kept for callers of the old response shape
          example: "9233"
        status:
          type: string
          description: >-
            literal "success" for start/shutdown; for reboot, the power state
            confirmed after it (e.g. running)
          example: success
        message:
          type: string
          description: start/shutdown only
          example: Dedicated server start operation completed
    dedicatedError:
      type: object
      properties:
        error:
          type: string
          description: customer-facing message
    dedicatedConsoleReadyResponse:
      type: object
      properties:
        status:
          type: string
          description: always "ready"
          example: ready
        service_id:
          type: string
          example: "9233"
        websocket_path:
          type: string
          description: >-
            route of step 2, the WebSocket noVNC must connect to, under the
            /v1/baremetal prefix of the gateway
          example: /v1/baremetal/9233/console/123/ws
        subprotocol:
          type: string
          example: binary
        joined:
          type: boolean
          description: true when an already open session was joined instead of a new one
        expires_at:
          type: string
          description: >-
            when the session ends at the latest (max duration, 4 h);
            it also ends after 15 min idle
          example: "2026-10-28T18:02:30Z"
    dedicatedServerStatusResponse:
      type: object
      properties:
        status:
          type: string
          enum:
            - running
            - halted
            - unknown
          example: running
        power_state:
          type: string
          description: power state (on, off, unknown)
          example: "on"
        service_status:
          type: string
          description: service status (active, suspended, ...)
          example: active
        live:
          type: boolean
          description: >-
            false when the state is the last known one (cached read, or a BMC
            that did not answer)
          example: false
        read_at:
          type: string
          example: "2026-10-29T18:36:05Z"
    dedicatedInfoResource:
      type: object
      properties:
        capacity:
          type: number
        usage:
          type: number
        text:
          type: string
    dedicatedInfoResponse:
      type: object
      properties:
        service_id:
          type: string
          example: "9233"
        device_id:
          type: string
          description: the service id; deprecated, kept for callers of the old response shape
          example: "9233"
        hostname:
          type: string
          example: server1.example.com
        status:
          type: string
          enum:
            - running
            - stopped
            - unknown
          example: running
        status_error:
          type: string
          description: why the power status could not be read (status is "unknown")
        power_state:
          type: string
          example: "on"
        service_status:
          type: string
          example: active
        live:
          type: boolean
        read_at:
          type: string
          example: "2026-10-29T18:36:05Z"
        provisioned:
          type: boolean
        installing:
          type: boolean
        location:
          type: string
          example: MVD
        os:
          type: string
          example: ubuntu-24.04
        ipv4:
          type: string
          example: 203.0.113.10
        ipv6:
          type: string
        ips:
          type: array
          items:
            type: object
            properties:
              name:
                type: string
              value:
                type: string
                example: 203.0.113.10
              additional:
                type: boolean
        additional_ips:
          type: array
          items:
            type: string
        bgp:
          type: boolean
        resources:
          type: object
          properties:
            cpu:
              $ref: "#/components/schemas/dedicatedInfoResource"
            ram:
              $ref: "#/components/schemas/dedicatedInfoResource"
            storage:
              $ref: "#/components/schemas/dedicatedInfoResource"
            bandwidth:
              $ref: "#/components/schemas/dedicatedInfoResource"
            transfer:
              type: object
              properties:
                capacity_tb:
                  type: number
                usage_bytes:
                  type: number
                text:
                  type: string
    ticketFile:
      type: object
      description: Inline file attachment (base64 content).
      properties:
        name:
          type: string
          example: screenshot.png
        contentType:
          type: string
          example: image/png
        content:
          type: string
          format: byte
          description: base64-encoded file content
    openTicketRequest:
      type: object
      required:
        - profileId
        - service
        - subject
        - message
      properties:
        profileId:
          type: integer
          description: must be an owned profile of the authenticated user
          example: 1
        department:
          type: string
          enum: [general, technical, billing, support]
          description: defaults to support when omitted
          example: technical
        service:
          type: string
          enum: [vps, baremetal, colocation, custom]
          example: vps
        serviceId:
          type: integer
          description: id of the concrete service; omit (or 0) when not tied to one
          example: 427
        subject:
          type: string
          example: BGP Activation Request - SID 427
        message:
          type: string
          example: Please activate BGP for my service.
        files:
          type: array
          items:
            $ref: "#/components/schemas/ticketFile"
    replyRequest:
      type: object
      required:
        - message
      properties:
        message:
          type: string
          example: Any update on this?
        files:
          type: array
          items:
            $ref: "#/components/schemas/ticketFile"
    closeRequest:
      type: object
      description: Optional body; only a close reason.
      properties:
        reason:
          type: string
          example: Issue resolved
    rateTicketRequest:
      type: object
      properties:
        stars:
          type: integer
          description: 1-5
          example: 5
        useful:
          type: boolean
          example: true
        comment:
          type: string
          example: Fast and helpful
    ticketCatalogEntry:
      type: object
      properties:
        code:
          type: string
          example: technical
        name:
          type: string
          example: Technical
    ticketReply:
      type: object
      properties:
        author:
          type: string
          description: user | admin
          example: user
        authorId:
          type: integer
          example: 1
        authorName:
          type: string
          example: John Doe
        message:
          type: string
        files:
          type: array
          items:
            $ref: "#/components/schemas/ticketFile"
        createdAt:
          type: string
          format: date-time
    ticketDetail:
      type: object
      properties:
        id:
          type: string
          example: 6f1c2b3a-0000-0000-0000-000000000000
        reference:
          type: string
          example: TCK-10456
        profileId:
          type: integer
        department:
          type: string
        service:
          type: string
        serviceId:
          type: integer
        location:
          type: string
        subject:
          type: string
        status:
          type: string
          description: display status (waiting | answered | closed)
        createdAt:
          type: string
          format: date-time
        lastReplyAt:
          type: string
          format: date-time
        replies:
          type: array
          items:
            $ref: "#/components/schemas/ticketReply"
        rating:
          $ref: "#/components/schemas/rateTicketRequest"
        reads:
          type: array
          items:
            type: object
            properties:
              side:
                type: string
              readerId:
                type: integer
              lastReadAt:
                type: string
                format: date-time
    ticketSummary:
      type: object
      properties:
        id:
          type: string
        reference:
          type: string
        profileId:
          type: integer
        department:
          type: string
        service:
          type: string
        serviceId:
          type: integer
        subject:
          type: string
        status:
          type: string
        hasUnread:
          type: boolean
        createdAt:
          type: string
          format: date-time
        lastReplyAt:
          type: string
          format: date-time
    ticketsResponse:
      type: object
      description: Pagination envelope with the standard paginated shape.
      properties:
        items:
          type: array
          items:
            $ref: "#/components/schemas/ticketSummary"
        totalItems:
          type: integer
        totalPages:
          type: integer
        currentPage:
          type: integer
        pageSize:
          type: integer
        counts:
          type: object
          additionalProperties:
            type: integer
          example: { total: 3, unread: 1 }
        facets:
          type: object
          properties:
            departments:
              type: array
              items:
                type: string
            services:
              type: array
              items:
                type: string
    ipName:
      type: object
      properties:
        ip:
          type: string
          example: 192.0.2.10
        name:
          type: string
          example: host.example.com
    ipNames:
      type: object
      description: All IPs of a service with their DNS names.
      properties:
        ipv4:
          $ref: "#/components/schemas/ipName"
        ipv6:
          $ref: "#/components/schemas/ipName"
        additionalIps:
          type: array
          items:
            $ref: "#/components/schemas/ipName"
    nameIpRequest:
      type: object
      properties:
        profileId:
          type: integer
          example: 1
        ip:
          type: string
          example: 192.0.2.10
        name:
          type: string
          example: host.example.com
    netboxIpDetail:
      type: object
      properties:
        address:
          type: string
          example: 192.0.2.10/24
        status:
          type: string
          example: active
        is_additional_ip_of:
          type: string
        service_id:
          type: integer
    successResponse:
      type: object
      properties:
        message:
          type: string
          example: IP named successfully
    invoicePartial:
      type: object
      description: Slim invoice used in the paginated listing.
      properties:
        id:
          type: integer
          example: 10456
        status:
          type: string
          example: Unpaid
        paymentMethod:
          type: string
          example: paypal
        nextDueDate:
          type: string
          example: "2026-04-06"
        date:
          type: string
          example: "2026-03-06"
        cycle:
          type: string
          example: Monthly
        total:
          type: string
          example: "114.00"
        currency:
          $ref: "#/components/schemas/currency"
    invoicesResponse:
      type: object
      description: Paginated invoices envelope, with the standard paginated shape.
      properties:
        items:
          type: array
          items:
            $ref: "#/components/schemas/invoicePartial"
        total:
          type: integer
        page:
          type: integer
        totalPages:
          type: integer
        counts:
          type: object
          additionalProperties:
            type: integer
          description: invoice counts per WHMCS status plus a "total" key (global, all pages)
          example: { total: 12, Paid: 9, Unpaid: 3 }
    invoicesTotal:
      type: object
      description: Aggregated sum of a client's invoices in a given status.
      properties:
        total:
          type: number
          example: 342.5
        currency:
          $ref: "#/components/schemas/currency"
    creditsTotal:
      type: object
      description: Aggregated sum of a client's credit balance.
      properties:
        total:
          type: number
          example: 25
        currency:
          $ref: "#/components/schemas/currency"
    chatSettings:
      type: object
      description: Public-safe widget settings.
      properties:
        enabled:
          type: boolean
          example: true
        agentAlias:
          type: string
          example: Support
    chatStartConversationRequest:
      type: object
      required:
        - serviceId
      properties:
        serviceId:
          type: integer
          example: 427
    chatSendMessageRequest:
      type: object
      properties:
        body:
          type: string
          example: Hi, I need help with my server
    chatRateConversationRequest:
      type: object
      required:
        - rating
      properties:
        rating:
          type: integer
          description: 1-5
          example: 5
        comment:
          type: string
    chatAttachment:
      type: object
      properties:
        id:
          type: integer
        filename:
          type: string
        mimeType:
          type: string
        sizeBytes:
          type: integer
        url:
          type: string
          description: internal, auth-guarded URL served by chat-server
        source:
          type: string
    chatMessage:
      type: object
      description: User-facing message (agent identity obfuscated).
      properties:
        id:
          type: integer
        conversationId:
          type: integer
        direction:
          type: string
        body:
          type: string
        senderName:
          type: string
        attachments:
          type: array
          items:
            $ref: "#/components/schemas/chatAttachment"
        createdAt:
          type: string
          format: date-time
    chatConversation:
      type: object
      properties:
        id:
          type: integer
        ticketId:
          type: string
        profileId:
          type: integer
        serviceId:
          type: integer
        status:
          type: string
        agentAlias:
          type: string
        lastActivityAt:
          type: string
          format: date-time
        closedAt:
          type: string
          format: date-time
        closeReason:
          type: string
        createdAt:
          type: string
          format: date-time
        rating:
          type: integer
        ratingComment:
          type: string
        ratedAt:
          type: string
          format: date-time
        note:
          type: string
        messageCount:
          type: integer
        serviceInfo:
          type: object
        userInfo:
          type: object
    hostnameUpdateRequest:
      type: object
      required:
        - hostname
      properties:
        hostname:
          type: string
          example: my.new.hostname.com
    serverLogEntry:
      type: object
      description: One entry of a service's server_events audit feed.
      properties:
        source:
          type: string
        id:
          type: string
        version:
          type: integer
        eventType:
          type: string
          example: server.os_installed
        payload:
          type: object
        createdAt:
          type: string
        ip:
          type: string
        clientId:
          type: string
    serverLogsFeed:
      type: object
      description: Paginated server_events feed for a service.
      properties:
        items:
          type: array
          items:
            $ref: "#/components/schemas/serverLogEntry"
        totalItems:
          type: integer
        totalPages:
          type: integer
        currentPage:
          type: integer
    statusReport:
      type: object
      description: Status-page incident report covering the service's location.
      properties:
        id:
          type: string
        title:
          type: string
        description:
          type: string
        created:
          type: string
          format: date-time
        percentage:
          type: integer
        resolvedAt:
          type: string
          format: date-time
        statusAlert:
          type: object
        statusProcess:
          type: object
        services:
          type: array
          items:
            type: object
        typesOfReport:
          type: array
          items:
            type: object
        locations:
          type: array
          items:
            type: object
    serviceReports:
      type: object
      description: Incident reports matching a service's type and location.
      properties:
        serviceId:
          type: integer
        serviceType:
          type: string
          example: vps
        location:
          type: string
        count:
          type: integer
        reports:
          type: array
          items:
            $ref: "#/components/schemas/statusReport"
    notification:
      type: object
      description: One customer-panel notification (read-model item).
      properties:
        id:
          type: string
        type:
          type: string
          example: server.os_installed
        group:
          type: string
          enum: [service, ticket, invoice, other]
        serviceId:
          type: string
        hostname:
          type: string
        location:
          type: string
        previousOs:
          type: string
        newOs:
          type: string
        ticketId:
          type: string
        ticketPublicId:
          type: string
        ticketSubject:
          type: string
        messagePreview:
          type: string
        invoiceId:
          type: integer
        total:
          type: string
        currency:
          $ref: "#/components/schemas/currency"
        subject:
          type: string
        createdAt:
          type: string
          format: date-time
        isRead:
          type: boolean
    notificationsResponse:
      type: object
      description: Paginated notifications envelope with the unread badge count.
      properties:
        items:
          type: array
          items:
            $ref: "#/components/schemas/notification"
        totalItems:
          type: integer
        totalPages:
          type: integer
        currentPage:
          type: integer
        pageSize:
          type: integer
        unreadCount:
          type: integer

paths:

  # ---------------------------------------------------------------------------
  # auth — authentication.
  # ---------------------------------------------------------------------------
  /v1/auth/login:
    post:
      tags:
        - auth
      summary: Login a user registered
      security: []
      requestBody:
        description: A json structure with user credentials
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                email:
                  type: string
                  example: john.doe@example.com
                password:
                  type: string
                  example: password
      responses:
        "200":
          description: A response with the authorization code in the body
          content:
            text/plain:
              schema:
                type: string
                example: cf930f26-60b3-4204-b307-994e66f136f3
        "401":
          description: Login failure
          content:
            text/plain:
              schema:
                type: string
                example: Email or Password Invalid
        "404":
          description: Status not found
        "500":
          description: Unexpected error
          content:
            text/plain:
              schema:
                type: string
                example: Unexpected Error
  /v1/auth/token:
    post:
      tags:
        - auth
      summary: Save token on user session
      security: []
      requestBody:
        description: A json structure with authorization code
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                code:
                  type: string
                  example: cf930f26-60b3-4204-b307-994e66f136f3
      responses:
        "200":
          description: Token in session
        "404":
          description: Status not found
        "500":
          description: Unexpected error
          content:
            text/plain:
              schema:
                type: string
                example: Unexpected Error
  /v1/auth/logout:
    post:
      tags:
        - auth
      summary: Logs out
      security: []
      responses:
        "200":
          description: user logged out
  /v1/auth/refresh:
    post:
      tags:
        - auth
      summary: Refresh the access token using the refresh token cookie
      security: []
      description: >-
        Reads the opaque refresh token from the HttpOnly `refresh_token` cookie,
        rotates it and issues a new access token. The new JWT is stored
        server-side in the session (never returned in the body) and the
        refresh token cookie is rotated.
      responses:
        "200":
          description: Access token refreshed; session updated and refresh token cookie rotated
        "401":
          description: Missing or invalid refresh token
        "500":
          description: Unexpected error
          content:
            text/plain:
              schema:
                type: string
                example: Unexpected Error
  /v1/auth/:
    get:
      tags:
        - auth
      summary: Authenticate a request via API key
      description: >-
        Validates the API key sent in the `X-API-Key` header and, on success,
        returns a short-lived bearer token in the `Authorization` response
        header. This is the endpoint where the API key is consumed: API clients
        add the `X-API-Key` header to their requests and the gateway calls this
        endpoint internally to authenticate them.
      responses:
        "200":
          description: >-
            Authenticated. The `Authorization` response header carries the
            `Bearer <jwt>` token.
        "401":
          description: Missing or invalid API key
        "500":
          description: Unexpected error
  /v1/auth/session:
    get:
      tags:
        - auth
      summary: Report whether the caller has a usable session
      description: >-
        Bootstrap endpoint for the frontend. ALWAYS returns 200 with
        `{"authenticated": bool}` so the client can branch on the body instead of
        catching a 401. A session is authenticated when the stored access token is
        still valid, or when it can be silently renewed from the HttpOnly
        `refresh_token` cookie — in which case the session is refreshed in place so
        the subsequent protected requests never race an expired token.
      security: []
      responses:
        "200":
          description: Authentication state
          content:
            application/json:
              schema:
                type: object
                properties:
                  authenticated:
                    type: boolean
                    example: true
  /v1/auth/apikeys:
    post:
      tags:
        - auth
      summary: Create an API key
      security:
        - SessionCookie: []
      description: >-
        Generates a new API key for the authenticated user. A user may hold
        several keys, so each call adds one (it never rotates existing keys). The
        plain value is returned only once in this response.
      requestBody:
        required: false
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  example: my-integration
                expires_at:
                  type: string
                  format: date-time
                  example: "2027-01-01T00:00:00Z"
                allowed_ips:
                  type: array
                  items:
                    type: string
                  nullable: true
                  description: >-
                    Optional allow-list of IPs/CIDRs (v4/v6) the key may be used
                    from. When empty or omitted, access is governed by the
                    server's API_KEY_EMPTY_ALLOWLIST_MODE (default deny_all; set
                    allow_all to leave the key unrestricted).
                  example: ["10.0.0.0/24", "203.0.113.5"]
      responses:
        "201":
          description: API key created
          content:
            application/json:
              schema:
                type: object
                properties:
                  api_key:
                    type: string
                    example: cpk_live_9f8e7d6c5b4a...
                  id:
                    type: string
                    format: uuid
                  key_prefix:
                    type: string
                    example: cpk_live_9f8e7d
                  name:
                    type: string
                    example: my-integration
                  expires_at:
                    type: string
                    format: date-time
                    nullable: true
                  created_at:
                    type: string
                    format: date-time
                  allowed_ips:
                    type: array
                    items:
                      type: string
                    nullable: true
                    example: ["10.0.0.0/24", "203.0.113.5"]
        "400":
          description: Invalid request body
        "401":
          description: No valid session
        "500":
          description: Unexpected error
    get:
      tags:
        - auth
      summary: List the user's API keys
      security:
        - SessionCookie: []
      description: >-
        Returns the metadata of every API key the authenticated user owns
        (prefix, name, last used, expiration, IP allow-list), newest first.
        Never returns the secret. Responds with an empty array when the user has
        no keys.
      responses:
        "200":
          description: API key metadata
          content:
            application/json:
              schema:
                type: array
                items:
                  type: object
                  properties:
                    id:
                      type: string
                      format: uuid
                    key_prefix:
                      type: string
                      example: cpk_live_9f8e7d
                    name:
                      type: string
                      example: my-integration
                    is_admin:
                      type: boolean
                    last_used_at:
                      type: string
                      format: date-time
                      nullable: true
                    expires_at:
                      type: string
                      format: date-time
                      nullable: true
                    active:
                      type: boolean
                    revoked:
                      type: boolean
                      description: >-
                        True when the key was manually revoked (via POST
                        /v1/auth/apikeys/{id}/revoke). A revoked key stays listed
                        as inactive, unlike a deleted one, and is distinct from a
                        key that merely expired (revoked=false).
                    revoked_at:
                      type: string
                      format: date-time
                      nullable: true
                    created_at:
                      type: string
                      format: date-time
                    updated_at:
                      type: string
                      format: date-time
                      description: >-
                        Last time the key row changed. Maintained by the database
                        and refreshed on any update, including key usage.
                    allowed_ips:
                      type: array
                      items:
                        type: string
                      nullable: true
                      example: ["10.0.0.0/24", "203.0.113.5"]
        "401":
          description: No valid session
        "500":
          description: Unexpected error

  /v1/auth/apikeys/{id}:
    patch:
      tags:
        - auth
      summary: Update one of the user's API keys
      security:
        - SessionCookie: []
      description: >-
        Replaces the IP allow-list of a single API key identified by its id,
        without rotating it. The key must belong to the authenticated user,
        otherwise a 404 is returned. When allowed_ips is empty or omitted, access
        is governed by the server's API_KEY_EMPTY_ALLOWLIST_MODE (default
        deny_all; set allow_all to leave the key unrestricted). The new
        restriction applies immediately.
      parameters:
        - name: id
          in: path
          required: true
          description: API key id
          schema:
            type: string
            format: uuid
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                allowed_ips:
                  type: array
                  items:
                    type: string
                  nullable: true
                  example: ["10.0.0.0/24", "203.0.113.5"]
      responses:
        "204":
          description: API key updated
        "400":
          description: Invalid request
        "401":
          description: No valid session
        "404":
          description: API key not found
        "500":
          description: Unexpected error
  /v1/auth/apikeys/{id}/revoke:
    post:
      tags:
        - auth
      summary: Revoke one of the user's API keys
      security:
        - SessionCookie: []
      description: >-
        Revokes a single API key identified by its id without deleting it. The
        key must belong to the authenticated user, otherwise a 404 is returned.
        The key stops authenticating immediately but stays in the listing as
        inactive (active=false, revoked=true, revoked_at set), so a manual
        revocation can be told apart from a key that merely expired. An already
        revoked or deleted key returns a 404. To remove the key entirely, use
        DELETE /v1/auth/apikeys/{id}.
      parameters:
        - name: id
          in: path
          required: true
          description: API key id
          schema:
            type: string
            format: uuid
      responses:
        "204":
          description: API key revoked
        "400":
          description: Invalid API key id
        "401":
          description: No valid session
        "404":
          description: API key not found
        "500":
          description: Unexpected error

  # ---------------------------------------------------------------------------
  # oidc — OpenID Connect provider (acts as IdP for SSO
  # to relying parties such as white-panel).
  #
  # Exposed under /v1/auth in the public facade (the gateway rewrites
  # /v1/auth/X -> /X, so the real internal routes live at the service root).
  # They are PUBLIC at the gateway/ingress without session auth: the relying
  # party reaches them by the `issuer` URL (which must include the /v1/auth
  # prefix) and each one resolves its own auth (browser session, PKCE or
  # client_secret). Wired only when OIDC_ISSUER is configured.
  # ---------------------------------------------------------------------------
  /v1/auth/.well-known/openid-configuration:
    get:
      tags:
        - oidc
      summary: OpenID Connect discovery document
      description: >-
        Public, unauthenticated. Lets a relying party discover the
        authorization, token and jwks endpoints and the provider capabilities.
      responses:
        "200":
          description: Discovery document
          content:
            application/json:
              schema:
                type: object
                properties:
                  issuer:
                    type: string
                    example: https://panel.ipxon.net/v1/auth
                  authorization_endpoint:
                    type: string
                    example: https://panel.ipxon.net/v1/auth/oidc/authorize
                  token_endpoint:
                    type: string
                    example: https://panel.ipxon.net/v1/auth/oidc/token
                  jwks_uri:
                    type: string
                    example: https://panel.ipxon.net/v1/auth/oidc/jwks
                  response_types_supported:
                    type: array
                    items:
                      type: string
                    example: ["code"]
                  subject_types_supported:
                    type: array
                    items:
                      type: string
                    example: ["public"]
                  id_token_signing_alg_values_supported:
                    type: array
                    items:
                      type: string
                    example: ["RS256"]
                  scopes_supported:
                    type: array
                    items:
                      type: string
                    example: ["openid", "email", "profile"]
                  token_endpoint_auth_methods_supported:
                    type: array
                    items:
                      type: string
                    example: ["client_secret_post"]
                  code_challenge_methods_supported:
                    type: array
                    items:
                      type: string
                    example: ["S256"]
                  grant_types_supported:
                    type: array
                    items:
                      type: string
                    example: ["authorization_code"]
  /v1/auth/oidc/jwks:
    get:
      tags:
        - oidc
      summary: JSON Web Key Set (public signing keys)
      description: >-
        Public, unauthenticated. Publishes the RSA public key(s) so a relying
        party can verify the `id_token` signature without sharing a secret.
      responses:
        "200":
          description: JWKS document
          content:
            application/json:
              schema:
                type: object
                properties:
                  keys:
                    type: array
                    items:
                      type: object
                      properties:
                        kty:
                          type: string
                          example: RSA
                        use:
                          type: string
                          example: sig
                        alg:
                          type: string
                          example: RS256
                        kid:
                          type: string
                          example: default
                        "n":
                          type: string
                          description: modulus (base64url)
                        e:
                          type: string
                          example: AQAB
  /v1/auth/oidc/authorize:
    get:
      tags:
        - oidc
      summary: Authorization endpoint (Authorization Code + PKCE)
      description: >-
        Browser-facing. Public at the gateway but requires the customer panel
        browser session cookie; if the session is missing/expired it refreshes
        silently or redirects to login with a `return_to` back to this URL.
        Validates `client_id`/`redirect_uri` and the selected `profile_id`, then
        redirects to the relying party's `redirect_uri` with a one-time `code`.
      parameters:
        - in: query
          name: response_type
          required: true
          schema:
            type: string
            enum: [code]
        - in: query
          name: client_id
          required: true
          schema:
            type: string
        - in: query
          name: redirect_uri
          required: true
          schema:
            type: string
        - in: query
          name: scope
          required: false
          schema:
            type: string
            example: openid email profile
        - in: query
          name: state
          required: false
          schema:
            type: string
        - in: query
          name: code_challenge
          required: true
          schema:
            type: string
        - in: query
          name: code_challenge_method
          required: true
          schema:
            type: string
            enum: [S256]
        - in: query
          name: profile_id
          required: false
          description: profile the user authorizes the SSO for
          schema:
            type: integer
      responses:
        "302":
          description: >-
            Redirect to the relying party's `redirect_uri` with `code` and
            `state`, or to login when there is no valid session.
        "400":
          description: Unknown client or redirect_uri not allowed / invalid request
  /v1/auth/oidc/token:
    post:
      tags:
        - oidc
      summary: Token endpoint (exchange authorization code for id_token)
      description: >-
        Server-to-server, called by the relying party. Public at the gateway;
        authenticated by client credentials (`client_secret_post`) plus the PKCE
        `code_verifier`. Not a session-authenticated endpoint.
      requestBody:
        required: true
        content:
          application/x-www-form-urlencoded:
            schema:
              type: object
              properties:
                grant_type:
                  type: string
                  enum: [authorization_code]
                code:
                  type: string
                redirect_uri:
                  type: string
                client_id:
                  type: string
                client_secret:
                  type: string
                code_verifier:
                  type: string
      responses:
        "200":
          description: Token response
          content:
            application/json:
              schema:
                type: object
                properties:
                  access_token:
                    type: string
                  id_token:
                    type: string
                    description: signed RS256 JWT
                  token_type:
                    type: string
                    example: Bearer
                  expires_in:
                    type: integer
                    example: 600
        "400":
          description: Invalid grant, client or PKCE verifier

  # ---------------------------------------------------------------------------
  # vps — Virtual Machine power actions and console.
  # ---------------------------------------------------------------------------
  /v1/vps/{serviceId}/console:
    get:
      tags:
        - vps
      summary: Get Virtual Machine Console
      parameters:
        - in: path
          name: serviceId
          required: true
          schema:
            type: string
          description: Service ID
      responses:
        "101":
          description: Switching Protocols to WebSocket
          content:
            application/json:
              schema:
                type: string
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    example: Console accessed successfully
                  sid:
                    type: string
                    example: "123"
        "400":
          description: Bad Request
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    example: 'Failed to find node: node not found'
        "404":
          description: Not Found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    example: No service found
        "500":
          description: Internal Server Error
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    example: Failed to parse result
    post:
      tags:
        - vps
      summary: Get VNC Ticket
      parameters:
        - in: path
          name: serviceId
          required: true
          schema:
            type: string
          description: Service ID
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  vncticket:
                    type: string
                    example: abcdef1234567890
        "400":
          description: Bad Request
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    example: 'Failed to find node: node not found'
        "404":
          description: Not Found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    example: No service found
        "500":
          description: Internal Server Error
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    example: Failed to parse result
  /v1/vps/{serviceId}/pause:
    post:
      tags:
        - vps
      summary: Pause a Virtual Machine
      parameters:
        - in: path
          name: serviceId
          required: true
          schema:
            type: string
          description: Service ID
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  SID:
                    type: string
                    example: "123456"
                  message:
                    type: string
                    example: Service successfully paused
        "400":
          description: Bad Request
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    example: 'Failed to find node: node not found'
        "404":
          description: Not Found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    example: No service found
        "500":
          description: Internal Server Error
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    example: Failed to parse result
  /v1/vps/{serviceId}/reboot:
    post:
      tags:
        - vps
      summary: Reboot a Virtual Machine
      parameters:
        - in: path
          name: serviceId
          required: true
          schema:
            type: string
          description: Service ID
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  SID:
                    type: string
                    example: "123456"
                  message:
                    type: string
                    example: Service successfully rebooted
        "400":
          description: Bad Request
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    example: 'Failed to find node: node not found'
        "404":
          description: Not Found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    example: No service found
        "500":
          description: Internal Server Error
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    example: Failed to parse result
  /v1/vps/{serviceId}/reset:
    post:
      tags:
        - vps
      summary: Reset a Virtual Machine
      parameters:
        - in: path
          name: serviceId
          required: true
          schema:
            type: string
          description: Service ID
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  SID:
                    type: string
                    example: "123456"
                  message:
                    type: string
                    example: Service successfully reset
        "400":
          description: Bad Request
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    example: 'Failed to find node: node not found'
        "404":
          description: Not Found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    example: No service found
        "500":
          description: Internal Server Error
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    example: Failed to parse result
  /v1/vps/{serviceId}/resume:
    post:
      tags:
        - vps
      summary: Resume a Virtual Machine
      parameters:
        - in: path
          name: serviceId
          required: true
          schema:
            type: string
          description: Service ID
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  SID:
                    type: string
                    example: "123456"
                  message:
                    type: string
                    example: Service successfully resumed
        "400":
          description: Bad Request
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    example: 'Failed to find node: node not found'
        "404":
          description: Not Found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    example: No service found
        "500":
          description: Internal Server Error
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    example: Failed to parse result
  /v1/vps/{serviceId}/shutdown:
    post:
      tags:
        - vps
      summary: Shutdown a Virtual Machine
      parameters:
        - in: path
          name: serviceId
          required: true
          schema:
            type: string
          description: Service ID
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  SID:
                    type: string
                    example: "123456"
                  message:
                    type: string
                    example: Service successfully stopped
        "400":
          description: Bad Request
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    example: 'Failed to find node: node not found'
        "404":
          description: Not Found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    example: No service found
        "500":
          description: Internal Server Error
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    example: Failed to parse result
  /v1/vps/{serviceId}/start:
    post:
      tags:
        - vps
      summary: Start a Virtual Machine
      parameters:
        - in: path
          name: serviceId
          required: true
          schema:
            type: string
          description: Service ID
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  SID:
                    type: string
                    example: "123456"
                  message:
                    type: string
                    example: Service successfully started
        "400":
          description: Bad Request
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    example: 'Failed to find node: node not found'
        "404":
          description: Not Found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    example: No service found
        "500":
          description: Internal Server Error
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    example: Failed to parse result
  /v1/vps/{serviceId}/status:
    get:
      tags:
        - vps
      summary: Get Virtual Machine Status
      parameters:
        - in: path
          name: serviceId
          required: true
          schema:
            type: string
          description: Service ID
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  qmpstatus:
                    type: string
                    example: running
                  uptime_days:
                    type: integer
                    example: 5
        "400":
          description: Bad Request
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    example: 'Failed to find node: node not found'
        "404":
          description: Not Found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    example: No service found
        "500":
          description: Internal Server Error
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    example: Failed to parse result
  /v1/vps/{serviceId}/stop:
    post:
      tags:
        - vps
      summary: Stop a Virtual Machine
      parameters:
        - in: path
          name: serviceId
          required: true
          schema:
            type: string
          description: Service ID
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  SID:
                    type: string
                    example: "123456"
                  message:
                    type: string
                    example: Service successfully stopped
        "400":
          description: Bad Request
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    example: 'Failed to find node: node not found'
        "404":
          description: Not Found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    example: No service found
        "500":
          description: Internal Server Error
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    example: Failed to parse result
  /v1/vps/{serviceId}/reinstall:
    post:
      tags:
        - vps
      summary: Reinstall a Virtual Machine with the given OS
      description: >-
        Event-sourced reinstall. A same-OS request reinstalls; a different OS
        performs a cross-OS upgrade. The login password is rotated before the
        reinstall. Ownership is derived from the service itself (its owning
        profile must be one carried in the caller's JWT), so no client id is
        needed in the path.
      parameters:
        - in: path
          name: serviceId
          required: true
          schema:
            type: integer
          description: service id
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - osValue
              properties:
                osValue:
                  type: string
                  description: name/identifier of the target operating system
                  example: Ubuntu 22.04
      responses:
        "202":
          description: Reinstall requested
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    example: Virtual Machine reinstall requested
                  serviceId:
                    type: integer
                    example: 427
                  osValue:
                    type: string
                    example: Ubuntu 22.04
        "400":
          description: Invalid service id, malformed body or missing required resources
        "403":
          description: Service does not belong to any of the caller's profiles
        "404":
          description: Service not found
        "409":
          description: Pending OS upgrade, or service not provisioned / currently installing
        "500":
          description: Internal Server Error
  /v1/vps/{serviceId}/hostname:
    put:
      tags:
        - vps
      summary: Update a Virtual Machine hostname
      description: >-
        Event-sourced hostname update. Ownership is derived from the service
        itself (its owning profile must be one carried in the caller's JWT), so
        no client id is needed in the path.
      parameters:
        - in: path
          name: serviceId
          required: true
          schema:
            type: integer
          description: service id
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/hostnameUpdateRequest"
      responses:
        "202":
          description: Hostname update requested
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    example: Virtual Machine hostname update requested
                  serviceId:
                    type: integer
                    example: 427
                  hostname:
                    type: string
                    example: my.new.hostname.com
        "400":
          description: Invalid service id or malformed body
        "403":
          description: Service does not belong to any of the caller's profiles
        "404":
          description: Service not found
        "500":
          description: Internal Server Error
  /v1/vps/{serviceId}/logs:
    get:
      tags:
        - vps
      summary: Get the stored server_events log feed for a Virtual Machine
      description: >-
        Read-only, paginated audit feed of the service's server_events stream.
        Ownership is derived from the service itself (no client id in the path).
      parameters:
        - in: path
          name: serviceId
          required: true
          schema:
            type: integer
          description: service id
        - in: query
          name: limit
          schema:
            type: integer
          description: items per page (default 100, max 500)
        - in: query
          name: page
          schema:
            type: integer
          description: page number (default 1)
        - in: query
          name: sortOrder
          schema:
            type: string
            enum: [desc, asc]
          description: sort by creation date (default desc)
      responses:
        "200":
          description: Paginated server_events feed
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/serverLogsFeed"
        "400":
          description: Invalid service id
        "403":
          description: Service does not belong to any of the caller's profiles
        "404":
          description: Service not found
        "500":
          description: Internal Server Error
  /v1/vps/{serviceId}/reports:
    get:
      tags:
        - vps
      summary: Get status-page incident reports matching a Virtual Machine's location
      parameters:
        - in: path
          name: serviceId
          required: true
          schema:
            type: integer
          description: service id
      responses:
        "200":
          description: Incident reports covering the service's type and location
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/serviceReports"
        "400":
          description: Invalid service id
        "403":
          description: Service does not belong to any of the caller's profiles
        "404":
          description: Service not found
        "502":
          description: Failed to reach the status service

  # ---------------------------------------------------------------------------
  # baremetal — dedicated server power actions and console
  # (mirror of the /vps power actions, under the /baremetal prefix).
  # ---------------------------------------------------------------------------
  /v1/baremetal/{serviceId}/console:
    get:
      tags:
        - baremetal
      summary: Open the dedicated server console
      description: >-
        Step 1 of a console access. Opens the KVM console (or joins
        the open one) and waits until it is ready, which can take up to ~2
        minutes. Answers only that the console is ready and the
        `websocket_path` noVNC must connect to (step 2, subprotocol `binary`,
        empty VNC password); the console url and session cookie never leave
        the service.
        Ownership is derived from the service: one of the caller's profiles must be the service's owning profile. The client id in the returned `websocket_path` is the service's owning profile.
      parameters:
        - in: path
          name: serviceId
          required: true
          schema:
            type: integer
          description: Service ID
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/dedicatedConsoleReadyResponse"
        "403":
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/dedicatedError"
        "404":
          description: Not Found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/dedicatedError"
        "409":
          description: Not provisioned, suspended or without server
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/dedicatedError"
        "429":
          description: Too many simultaneous consoles
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/dedicatedError"
        "500":
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/dedicatedError"
        "502":
          description: BMC not responding
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/dedicatedError"
  /v1/baremetal/{serviceId}/console/{cid}/ws:
    get:
      tags:
        - baremetal
      summary: Dedicated server console websocket
      description: >-
        Step 2 of a console access: upgrades to a WebSocket (subprotocol
        `binary`) carrying RFB, for noVNC to connect to after the console
        request answered `status: "ready"` with this path as `websocket_path`.
        The backend relays it to the console session.
        When no session is open (it expired, or step 1 was not called) the
        websocket is accepted and closed with code 1013 and a reason. Path
        params must be integers. `serviceId` = service id, `cid` = customer id
        (kept in the path because noVNC cannot send headers of its own).
      parameters:
        - in: path
          name: serviceId
          required: true
          schema:
            type: integer
          description: Service ID
        - in: path
          name: cid
          required: true
          schema:
            type: integer
          description: Customer ID
      responses:
        "101":
          description: Switching Protocols to WebSocket
        "403":
          description: Forbidden
        "404":
          description: Not Found
        "409":
          description: Conflict
        "500":
          description: Internal Server Error
  /v1/baremetal/{serviceId}/status:
    get:
      tags:
        - baremetal
      summary: Get dedicated server status
      description: >-
        Power status of the server. By default the last known
        state is returned (cached: instant, no BMC access), which is what
        listings and periodic polling need. Pass `live=true` for a live BMC
        read (3-4 s), for detail views and right after an action.
        Ownership is derived from the service: one of the caller's profiles must be the service's owning profile.
      parameters:
        - in: path
          name: serviceId
          required: true
          schema:
            type: integer
          description: Service ID
        - in: query
          name: live
          required: false
          schema:
            type: boolean
          description: read the state live from the BMC instead of the last known one
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/dedicatedServerStatusResponse"
        "404":
          description: Not Found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/dedicatedError"
        "409":
          description: Service pending/terminated or without server
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/dedicatedError"
        "500":
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/dedicatedError"
        "502":
          description: BMC not responding
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/dedicatedError"
  /v1/baremetal/{serviceId}/info:
    get:
      tags:
        - baremetal
      summary: Get dedicated server info
      description: >-
        Server info built from the service's own data (hostname, IPs, plan
        resources, location, OS) and its live power status. If
        the power status cannot be read the info is still returned with status
        "unknown" and the reason in `status_error`.
        Ownership is derived from the service: one of the caller's profiles must be the service's owning profile.
      parameters:
        - in: path
          name: serviceId
          required: true
          schema:
            type: integer
          description: Service ID
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/dedicatedInfoResponse"
        "404":
          description: Not Found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/dedicatedError"
        "500":
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/dedicatedError"
  /v1/baremetal/{serviceId}/start:
    post:
      tags:
        - baremetal
      summary: Start a dedicated server
      description: >-
        Powers the server on. An invalid state transition
        (e.g. the server is already running) is rejected with 409.
        Ownership is derived from the service: one of the caller's profiles must be the service's owning profile.
      parameters:
        - in: path
          name: serviceId
          required: true
          schema:
            type: integer
          description: Service ID
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/dedicatedStatusResponse"
        "409":
          description: Invalid state transition, suspended or without server
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/dedicatedError"
        "500":
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/dedicatedError"
  /v1/baremetal/{serviceId}/shutdown:
    post:
      tags:
        - baremetal
      summary: Shutdown a dedicated server
      description: >-
        Shuts the server down. An invalid state transition
        (e.g. the server is already stopped) is rejected with 409.
        Ownership is derived from the service: one of the caller's profiles must be the service's owning profile.
      parameters:
        - in: path
          name: serviceId
          required: true
          schema:
            type: integer
          description: Service ID
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/dedicatedStatusResponse"
        "409":
          description: Invalid state transition, suspended or without server
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/dedicatedError"
        "500":
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/dedicatedError"
  /v1/baremetal/{serviceId}/reboot:
    post:
      tags:
        - baremetal
      summary: Reboot a dedicated server
      description: >-
        Reboots the server (synchronous, up to ~30 s). On
        success `status` is the power state confirmed after the reboot (e.g.
        running).
        Ownership is derived from the service: one of the caller's profiles must be the service's owning profile.
      parameters:
        - in: path
          name: serviceId
          required: true
          schema:
            type: integer
          description: Service ID
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/dedicatedStatusResponse"
        "409":
          description: Invalid state transition, suspended or without server
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/dedicatedError"
        "429":
          description: Too many actions in a short time (reboot cooldown)
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/dedicatedError"
        "500":
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/dedicatedError"
        "502":
          description: BMC not responding
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/dedicatedError"
  /v1/baremetal/{serviceId}/hostname:
    put:
      tags:
        - baremetal
      summary: Update a dedicated server hostname
      description: >-
        Event-sourced hostname update. Ownership is derived from the service
        itself (its owning profile must be one carried in the caller's JWT), so
        no client id is needed in the path.
      parameters:
        - in: path
          name: serviceId
          required: true
          schema:
            type: integer
          description: service id
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/hostnameUpdateRequest"
      responses:
        "202":
          description: Hostname update requested
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    example: Dedicated server hostname update requested
                  serviceId:
                    type: integer
                    example: 427
                  hostname:
                    type: string
                    example: my.new.hostname.com
        "400":
          description: Invalid service id or malformed body
        "403":
          description: Service does not belong to any of the caller's profiles
        "404":
          description: Service not found
        "500":
          description: Internal Server Error
  /v1/baremetal/{serviceId}/logs:
    get:
      tags:
        - baremetal
      summary: Get the stored server_events log feed for a dedicated server
      description: >-
        Read-only, paginated audit feed of the service's server_events stream.
        Ownership is derived from the service itself (no client id in the path).
      parameters:
        - in: path
          name: serviceId
          required: true
          schema:
            type: integer
          description: service id
        - in: query
          name: limit
          schema:
            type: integer
          description: items per page (default 100, max 500)
        - in: query
          name: page
          schema:
            type: integer
          description: page number (default 1)
        - in: query
          name: sortOrder
          schema:
            type: string
            enum: [desc, asc]
          description: sort by creation date (default desc)
      responses:
        "200":
          description: Paginated server_events feed
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/serverLogsFeed"
        "400":
          description: Invalid service id
        "403":
          description: Service does not belong to any of the caller's profiles
        "404":
          description: Service not found
        "500":
          description: Internal Server Error
  /v1/baremetal/{serviceId}/reports:
    get:
      tags:
        - baremetal
      summary: Get status-page incident reports matching a dedicated server's location
      parameters:
        - in: path
          name: serviceId
          required: true
          schema:
            type: integer
          description: service id
      responses:
        "200":
          description: Incident reports covering the service's type and location
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/serviceReports"
        "400":
          description: Invalid service id
        "403":
          description: Service does not belong to any of the caller's profiles
        "404":
          description: Service not found
        "502":
          description: Failed to reach the status service

  # ---------------------------------------------------------------------------
  # ip — DNS names and IP listing per service.
  # Public (customer account) endpoints only; admin-only IP routes omitted.
  # ---------------------------------------------------------------------------
  /v1/ip/services/{serviceId}/names:
    get:
      tags:
        - ip
      summary: Get IP names for a service
      parameters:
        - in: path
          name: serviceId
          required: true
          schema:
            type: integer
          description: service id
      responses:
        "200":
          description: Service IP names
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ipNames"
        "400":
          description: Invalid service ID
        "401":
          description: Authorization context invalid or missing JWT token
        "403":
          description: "Access denied: server does not belong to authorized profiles"
        "404":
          description: Service/server not found
        "500":
          description: Failed to get IP names or internal server error
    post:
      tags:
        - ip
      summary: Assign a DNS name to an IP address of a service
      parameters:
        - in: path
          name: serviceId
          required: true
          schema:
            type: integer
          description: service id
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/nameIpRequest"
      responses:
        "200":
          description: IP named successfully
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/successResponse"
        "400":
          description: Invalid service ID, request format, or missing required fields
        "401":
          description: Authorization context invalid or missing JWT token
        "403":
          description: "Access denied: server does not belong to authorized profiles"
        "404":
          description: Service/server not found
        "500":
          description: Command execution failed or internal server error
  /v1/ip/services/{serviceId}/ips:
    get:
      tags:
        - ip
      summary: Get service IPs from Netbox
      parameters:
        - in: path
          name: serviceId
          required: true
          schema:
            type: integer
          description: service id
      responses:
        "200":
          description: IP addresses assigned to the service
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/netboxIpDetail"
        "400":
          description: Invalid service ID
        "401":
          description: Authorization context invalid or missing JWT token
        "403":
          description: "Access denied: server does not belong to authorized profiles"
        "404":
          description: Service/server not found
        "500":
          description: Internal server error

  # ---------------------------------------------------------------------------
  # billing — service cancellation, invoices and credits
  # Profile-scoped; reads hit WHMCS.
  # ---------------------------------------------------------------------------
  /v1/billing/:
    post:
      tags:
        - billing
      summary: Create order
      description: Create a new billing order.
      requestBody:
        description: Order details
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/order"
      responses:
        "200":
          description: ID of the created order
          content:
            text/plain:
              schema:
                type: string
                example: "10001"
        "403":
          description: Forbidden
        "404":
          description: Not found
        "500":
          description: Internal Server Error
  /v1/billing/orders/{id}:
    get:
      tags:
        - billing
      summary: Get an order
      description: >-
        Return the order's linked invoice id together with its discount, raw total
        value and currency descriptor, read directly from the WHMCS database. Value
        and currency are returned separately (not a pre-formatted string). The order
        must belong to the profile provided as a query parameter (the WHMCS client id).
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: integer
          description: Order ID
        - in: query
          name: profileId
          required: true
          schema:
            type: integer
          description: Profile ID (WHMCS client id)
          example: 1
      responses:
        "200":
          description: Order details
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/orderResponse"
        "400":
          description: Bad Request
        "403":
          description: Forbidden
        "404":
          description: Order not found
        "500":
          description: Internal Server Error
  /v1/billing/{serviceId}/cancel:
    post:
      tags:
        - billing
      summary: Request cancellation of a service
      description: >-
        Requests service cancellation. On success returns an empty 200 body.
        Note: the backend only reads `profileId`, `reason` and `type`; the
        `description` field sent by the panel is currently ignored.
      parameters:
        - in: path
          name: serviceId
          required: true
          schema:
            type: number
          description: specify the service id
          example: 427
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                profileId:
                  type: number
                  description: used for the billing authorization check
                  example: 1
                reason:
                  type: string
                  example: Too expensive
                type:
                  type: string
                  description: cancellation type (e.g. Immediate, EndOfBillingPeriod)
                  example: EndOfBillingPeriod
      responses:
        "200":
          description: Cancellation requested (empty body)
        "404":
          description: Malformed body or billing record not found
        "409":
          description: Existing Cancellation Request
        "500":
          description: Internal Server Error
  /v1/billing/invoices:
    get:
      tags:
        - billing
      summary: List invoices of a profile (paginated)
      description: >-
        Slim, paginated list of the profile's invoices read from WHMCS.
        Supports status/date/free-text filters and sorting. When both date
        ranges are supplied they are OR'd.
      parameters:
        - in: query
          name: profileId
          required: true
          schema:
            type: integer
          description: profile id (WHMCS client id)
          example: 1
        - in: query
          name: page
          schema:
            type: integer
          description: page number (1-indexed, default 1)
        - in: query
          name: status
          schema:
            type: string
          description: one or more WHMCS statuses, comma-separated (e.g. Paid,Unpaid). Case-insensitive.
        - in: query
          name: search
          schema:
            type: string
          description: case-insensitive substring across id, status, payment method, total, dates and cycle
        - in: query
          name: dateFrom
          schema:
            type: string
          description: invoice date on or after (YYYY-MM-DD)
        - in: query
          name: dateTo
          schema:
            type: string
          description: invoice date on or before (YYYY-MM-DD)
        - in: query
          name: nextDueDateFrom
          schema:
            type: string
          description: due date on or after (YYYY-MM-DD)
        - in: query
          name: nextDueDateTo
          schema:
            type: string
          description: due date on or before (YYYY-MM-DD)
        - in: query
          name: orderName
          schema:
            type: string
            enum: [id, status, paymentMethod, nextDueDate, date, cycle, total]
          description: sort field
        - in: query
          name: orderType
          schema:
            type: integer
            enum: [1, -1, 0]
          description: sort direction (1 asc, -1 desc, 0 default)
      responses:
        "200":
          description: Paginated invoices
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/invoicesResponse"
        "400":
          description: Bad Request
        "403":
          description: Forbidden
        "500":
          description: Internal Server Error
  /v1/billing/invoices/unpaid-total:
    get:
      tags:
        - billing
      summary: Get the sum of a profile's unpaid invoices
      parameters:
        - in: query
          name: profileId
          required: true
          schema:
            type: integer
          description: profile id
          example: 1
      responses:
        "200":
          description: Unpaid invoices total
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/invoicesTotal"
        "403":
          description: Forbidden
        "500":
          description: Internal Server Error
  /v1/billing/invoices/{id}:
    get:
      tags:
        - billing
      summary: Redirect to the authenticated WHMCS invoice view
      description: >-
        Generates a single-use WHMCS SSO token for the invoice owner and
        redirects the browser to the WHMCS invoice view (skips the login
        screen). The invoice must belong to the given profile.
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: integer
          description: invoice id
        - in: query
          name: profileId
          required: true
          schema:
            type: integer
          description: profile id
          example: 1
      responses:
        "302":
          description: Redirect to the authenticated WHMCS invoice view
        "400":
          description: Bad Request
        "403":
          description: Forbidden
        "404":
          description: Invoice not found
        "500":
          description: Internal Server Error
  /v1/billing/credits:
    get:
      tags:
        - billing
      summary: Get a profile's credit balance total
      parameters:
        - in: query
          name: profileId
          required: true
          schema:
            type: integer
          description: profile id
          example: 1
      responses:
        "200":
          description: Credits total
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/creditsTotal"
        "403":
          description: Forbidden
        "500":
          description: Internal Server Error

  # ---------------------------------------------------------------------------
  # tickets — support tickets. Public (customer
  # account) endpoints only; admin-only routes (e.g. admin replies) omitted.
  # ---------------------------------------------------------------------------
  /v1/tickets:
    get:
      tags:
        - tickets
      summary: List tickets of the authenticated user (paginated)
      parameters:
        - in: query
          name: page
          schema:
            type: integer
          description: page, 1-indexed
          example: 1
        - in: query
          name: profileId
          schema:
            type: integer
          description: filter by a single owned profile id
        - in: query
          name: department
          schema:
            type: string
            enum: [general, technical, billing]
        - in: query
          name: service
          schema:
            type: string
            enum: [vps, baremetal, colocation, custom]
        - in: query
          name: status
          schema:
            type: string
            enum: [waiting, answered, closed]
          description: display status
        - in: query
          name: unread
          schema:
            type: boolean
          description: only tickets unread by the viewer
      responses:
        "200":
          description: A paginated page of tickets
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ticketsResponse"
        "403":
          description: Requested profile does not belong to the authenticated user
    post:
      tags:
        - tickets
      summary: Open a new ticket
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/openTicketRequest"
      responses:
        "202":
          description: Ticket accepted for creation
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    example: 6f1c2b3a-0000-0000-0000-000000000000
                  reference:
                    type: string
                    example: TCK-10456
        "400":
          description: Malformed body or invalid file content
        "403":
          description: Profile does not belong to the authenticated user
  /v1/tickets/departments:
    get:
      tags:
        - tickets
      summary: List ticket departments (catalog)
      responses:
        "200":
          description: Ordered department catalog
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/ticketCatalogEntry"
  /v1/tickets/services:
    get:
      tags:
        - tickets
      summary: List ticket services (catalog)
      responses:
        "200":
          description: Ordered service catalog
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/ticketCatalogEntry"
  /v1/tickets/{id}:
    get:
      tags:
        - tickets
      summary: Get a ticket by id (reconstructed from its event stream)
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: ticket id
      responses:
        "200":
          description: The ticket detail
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ticketDetail"
        "403":
          description: Ticket does not belong to the authenticated user
        "404":
          description: Not found
  /v1/tickets/{id}/stream:
    get:
      tags:
        - tickets
      summary: Stream a ticket thread over WebSocket (real-time replies)
      description: >-
        Upgrades to a WebSocket connection. The first frame is a
        `{type:"snapshot"}` envelope carrying the full ticket detail; every
        following frame is a `{type:"reply"}` or `{type:"status"}` delta. Auth
        and ownership are enforced on the upgrade request.
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: ticket id
      responses:
        "101":
          description: Switching Protocols
        "403":
          description: Ticket does not belong to the authenticated user
        "404":
          description: Not found
  /v1/tickets/{id}/replies:
    post:
      tags:
        - tickets
      summary: Reply to a ticket as the owning user
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: ticket id
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/replyRequest"
      responses:
        "202":
          description: Reply accepted
        "400":
          description: Malformed body or invalid file content
  /v1/tickets/{id}/close:
    post:
      tags:
        - tickets
      summary: Close a ticket
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: ticket id
      requestBody:
        required: false
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/closeRequest"
      responses:
        "202":
          description: Close accepted
  /v1/tickets/{id}/rate:
    post:
      tags:
        - tickets
      summary: Rate a closed ticket (optional feedback by the owning user)
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: ticket id
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/rateTicketRequest"
      responses:
        "202":
          description: Rating accepted
        "400":
          description: Invalid rating (stars must be 1-5)
        "409":
          description: Ticket is not closed

  # ---------------------------------------------------------------------------
  # chat — customer support chat (chat-server). Public (customer account,
  # profile-scoped) endpoints only; admin and Slack webhook routes are omitted.
  # ---------------------------------------------------------------------------
  /v1/chat/profiles/{profileId}/settings:
    get:
      tags:
        - chat
      summary: Get public chat widget settings for a profile
      parameters:
        - in: path
          name: profileId
          required: true
          schema:
            type: integer
          description: customer profile id
      responses:
        "200":
          description: Public-safe widget settings
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/chatSettings"
  /v1/chat/profiles/{profileId}/conversations:
    get:
      tags:
        - chat
      summary: List the profile's conversations
      parameters:
        - in: path
          name: profileId
          required: true
          schema:
            type: integer
          description: customer profile id
        - in: query
          name: status
          schema:
            type: string
          description: filter by status
        - in: query
          name: page
          schema:
            type: integer
          description: page number (default 1)
        - in: query
          name: pageSize
          schema:
            type: integer
          description: page size (default 20)
      responses:
        "200":
          description: Envelope with a conversations array
          content:
            application/json:
              schema:
                type: object
                properties:
                  conversations:
                    type: array
                    items:
                      $ref: "#/components/schemas/chatConversation"
    post:
      tags:
        - chat
      summary: Start a conversation
      parameters:
        - in: path
          name: profileId
          required: true
          schema:
            type: integer
          description: customer profile id
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/chatStartConversationRequest"
      responses:
        "201":
          description: Conversation created
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/chatConversation"
        "400":
          description: Invalid request
        "403":
          description: Banned
        "409":
          description: Outside schedule
  /v1/chat/profiles/{profileId}/conversations/{conversationId}:
    get:
      tags:
        - chat
      summary: Get a conversation
      parameters:
        - in: path
          name: profileId
          required: true
          schema:
            type: integer
          description: customer profile id
        - in: path
          name: conversationId
          required: true
          schema:
            type: integer
          description: conversation id
      responses:
        "200":
          description: The conversation
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/chatConversation"
        "404":
          description: Not found or not owned
  /v1/chat/profiles/{profileId}/conversations/{conversationId}/messages:
    get:
      tags:
        - chat
      summary: List conversation messages
      parameters:
        - in: path
          name: profileId
          required: true
          schema:
            type: integer
          description: customer profile id
        - in: path
          name: conversationId
          required: true
          schema:
            type: integer
          description: conversation id
        - in: query
          name: afterId
          schema:
            type: integer
          description: return messages after this id (ascending)
        - in: query
          name: limit
          schema:
            type: integer
          description: max messages (default 100)
      responses:
        "200":
          description: Envelope with a messages array
          content:
            application/json:
              schema:
                type: object
                properties:
                  messages:
                    type: array
                    items:
                      $ref: "#/components/schemas/chatMessage"
    post:
      tags:
        - chat
      summary: Send a message
      parameters:
        - in: path
          name: profileId
          required: true
          schema:
            type: integer
          description: customer profile id
        - in: path
          name: conversationId
          required: true
          schema:
            type: integer
          description: conversation id
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/chatSendMessageRequest"
      responses:
        "201":
          description: Message created
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/chatMessage"
        "409":
          description: Conversation closed
        "429":
          description: Flood limit reached
  /v1/chat/profiles/{profileId}/conversations/{conversationId}/rating:
    post:
      tags:
        - chat
      summary: Rate a conversation
      parameters:
        - in: path
          name: profileId
          required: true
          schema:
            type: integer
          description: customer profile id
        - in: path
          name: conversationId
          required: true
          schema:
            type: integer
          description: conversation id
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/chatRateConversationRequest"
      responses:
        "200":
          description: Rated conversation
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/chatConversation"
        "400":
          description: Invalid rating
  /v1/chat/profiles/{profileId}/conversations/{conversationId}/close:
    post:
      tags:
        - chat
      summary: Close my conversation
      parameters:
        - in: path
          name: profileId
          required: true
          schema:
            type: integer
          description: customer profile id
        - in: path
          name: conversationId
          required: true
          schema:
            type: integer
          description: conversation id
      responses:
        "200":
          description: Closed conversation
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/chatConversation"
  /v1/chat/profiles/{profileId}/conversations/{conversationId}/attachments:
    post:
      tags:
        - chat
      summary: Upload an attachment
      parameters:
        - in: path
          name: profileId
          required: true
          schema:
            type: integer
          description: customer profile id
        - in: path
          name: conversationId
          required: true
          schema:
            type: integer
          description: conversation id
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              required:
                - file
              properties:
                file:
                  type: string
                  format: binary
                  description: file to upload
      responses:
        "201":
          description: Attachment message created
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/chatMessage"
        "413":
          description: File too large
        "415":
          description: Unsupported file type
  /v1/chat/profiles/{profileId}/conversations/{conversationId}/attachments/{attachmentId}:
    get:
      tags:
        - chat
      summary: Download an attachment
      parameters:
        - in: path
          name: profileId
          required: true
          schema:
            type: integer
          description: customer profile id
        - in: path
          name: conversationId
          required: true
          schema:
            type: integer
          description: conversation id
        - in: path
          name: attachmentId
          required: true
          schema:
            type: integer
          description: attachment id
      responses:
        "200":
          description: Attachment stream
          content:
            application/octet-stream:
              schema:
                type: string
                format: binary
        "404":
          description: Not found
  /v1/chat/profiles/{profileId}/conversations/{conversationId}/ws:
    get:
      tags:
        - chat
      summary: Conversation WebSocket stream (real-time events)
      description: >-
        Upgrades to a WebSocket that streams real-time conversation events. Auth
        and ownership are enforced on the upgrade; the JWT is passed via the
        `token` query param (WebSocket cannot send the Authorization header).
      parameters:
        - in: path
          name: profileId
          required: true
          schema:
            type: integer
          description: customer profile id
        - in: path
          name: conversationId
          required: true
          schema:
            type: integer
          description: conversation id
        - in: query
          name: token
          required: true
          schema:
            type: string
          description: JWT (WebSocket cannot send the Authorization header)
      responses:
        "101":
          description: Switching Protocols

  # ---------------------------------------------------------------------------
  # notifications — customer-panel notification feed.
  # Per-profile read-model; the profile id is a query param validated against
  # the JWT. Admin/config and rebuild routes are omitted.
  # ---------------------------------------------------------------------------
  /v1/notifications:
    get:
      tags:
        - notifications
      summary: Get the notification feed
      parameters:
        - in: query
          name: profileId
          required: true
          schema:
            type: integer
          description: profile id (validated against the JWT)
        - in: query
          name: page
          schema:
            type: integer
          description: page number (default 1)
        - in: query
          name: pageSize
          schema:
            type: integer
          description: items per page (default 10, max 100)
        - in: query
          name: group
          schema:
            type: string
            enum: [service, ticket, invoice, other]
          description: filter to a single group; omit for the full feed
      responses:
        "200":
          description: Paginated notifications with the unread badge count
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/notificationsResponse"
        "403":
          description: Profile does not belong to the authenticated user
  /v1/notifications/read:
    post:
      tags:
        - notifications
      summary: Mark the profile's notifications as read
      parameters:
        - in: query
          name: profileId
          required: true
          schema:
            type: integer
          description: profile id (validated against the JWT)
      responses:
        "204":
          description: Notifications marked as read
        "403":
          description: Profile does not belong to the authenticated user
  /v1/notifications/stream:
    get:
      tags:
        - notifications
      summary: Stream the notification feed (WebSocket)
      description: >-
        Upgrades to a WebSocket. The first frame is a snapshot page of the feed;
        subsequent frames push new notifications in real time.
      parameters:
        - in: query
          name: profileId
          required: true
          schema:
            type: integer
          description: profile id (validated against the JWT)
        - in: query
          name: page
          schema:
            type: integer
          description: snapshot page number (1-indexed)
        - in: query
          name: pageSize
          schema:
            type: integer
          description: snapshot items per page (default 20, max 100)
      responses:
        "101":
          description: Switching Protocols

  # ---------------------------------------------------------------------------
  # query — profiles, service listing, detail, billing, metrics, usage and
  # OS reinstall data. All under the /query gateway prefix.
  # ---------------------------------------------------------------------------
  /v1/query/profiles:
    get:
      tags:
        - query
      summary: Get profiles list of a user
      parameters:
        - in: query
          name: permission
          schema:
            type: string
          description: >-
            Its mere PRESENCE (any value, even empty) switches the response to
            the authorized-profiles shape (id, name, lastname, country,
            authorized). When absent, the default profiles shape is returned
            (id, name, lastname, company, country, owner).
          example: orders
      responses:
        "200":
          description: A JSON response with user's profiles
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/profile"
              examples:
                Profiles:
                  $ref: "#/components/schemas/profile/examples/Profiles"
                AuthorizedProfiles:
                  $ref: "#/components/schemas/profile/examples/AuthorizedProfiles"
  /v1/query/profiles/{profileId}/paymentmethods:
    get:
      tags:
        - query
      summary: List payment methods for a profile
      description: >-
        Returns the payment methods available for a profile. Consumed by the
        checkout flow (`useFetchPaymentMethods`).
      parameters:
        - in: path
          name: profileId
          required: true
          schema:
            type: number
          description: specify the profile id
          example: 1
      responses:
        "200":
          description: A JSON array of payment methods
          content:
            application/json:
              schema:
                type: array
                items:
                  type: object
                  properties:
                    module:
                      type: string
                      example: stripe
                    name:
                      type: string
                      example: Credit Card
        "500":
          description: Internal Server Error
  /v1/query/profiles/{profileId}/services:
    get:
      tags:
        - query
      summary: Get a paginated page of services of a profile
      description: >-
        Returns a page of services with server-side ordering and filtering.
        Page size is fixed at 10 (there is no configurable page size).
        Note: the panel currently also sends `pageSize` and `search` query
        params, but the service ignores them.
      parameters:
        - in: path
          name: profileId
          required: true
          schema:
            type: number
          description: specify the profile id
          example: 1
        - in: query
          name: page
          schema:
            type: integer
          description: 1-based page number (defaults to 1 when < 1)
          example: 1
        - in: query
          name: orderName
          schema:
            type: string
          description: field to order by
          example: name
        - in: query
          name: orderType
          schema:
            type: integer
            enum: [-1, 0, 1]
          description: 1 ascending, -1 descending, 0 no sort (any other value -> 400)
          example: 1
        - in: query
          name: billingStatus
          schema:
            type: string
          description: billing status filter (Active, Pending, Suspended, Cancelled, Fraud)
          example: Active
        - in: query
          name: service
          schema:
            type: string
          description: service type filter
          example: vps
        - in: query
          name: location
          schema:
            type: string
          description: IATA location code filter
          example: scl
        - in: query
          name: status
          schema:
            type: string
          description: power status filter (running, stopped, paused, unknown)
          example: running
      responses:
        "200":
          description: A JSON envelope with the requested page of services
          content:
            application/json:
              schema:
                type: object
                properties:
                  services:
                    type: array
                    items:
                      $ref: "#/components/schemas/servicePartial"
                  total:
                    type: integer
                    description: total number of services matching the query
                    example: 42
                  page:
                    type: integer
                    description: echoes the requested page
                    example: 1
                  totalPages:
                    type: integer
                    description: ceil(total / 10)
                    example: 5
        "400":
          description: Invalid query parameters (bad binding or orderType not in -1/0/1)
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    example: OrderType must be 1 or -1
        "500":
          description: Internal Server Error
  /v1/query/profiles/{profileId}/services/{serviceId}:
    get:
      tags:
        - query
      summary: Get a single service by id
      parameters:
        - in: path
          name: profileId
          required: true
          schema:
            type: number
          description: specify the profile id
          example: 1
        - in: path
          name: serviceId
          required: true
          schema:
            type: number
          description: specify the service id
          example: 427
      responses:
        "200":
          description: A JSON response with the full service information
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/service"
        "400":
          description: Invalid serviceId parameter
        "404":
          description: Service not found
        "500":
          description: Internal Server Error
  /v1/query/profiles/{profileId}/services/{serviceId}/billing:
    get:
      tags:
        - query
      summary: Get billing information for a service
      parameters:
        - in: path
          name: profileId
          required: true
          schema:
            type: number
          description: specify the profile id
          example: 1
        - in: path
          name: serviceId
          required: true
          schema:
            type: number
          description: specify the service id
          example: 427
      responses:
        "200":
          description: A JSON response with billing details
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/billing"
        "400":
          description: Invalid serviceId parameter
        "404":
          description: Service not found
        "500":
          description: Internal Server Error
  /v1/query/profiles/{profileId}/services/{serviceId}/metrics:
    get:
      tags:
        - query
      summary: Get service metrics for a time range
      parameters:
        - in: path
          name: profileId
          required: true
          schema:
            type: number
          description: specify the profile id
          example: 1
        - in: path
          name: serviceId
          required: true
          schema:
            type: number
          description: specify the service id
          example: 427
        - in: query
          name: start
          required: true
          schema:
            type: string
            format: date-time
          description: RFC3339 UTC start of the range
          example: "2024-01-01T00:00:00.000Z"
        - in: query
          name: stop
          required: true
          schema:
            type: string
            format: date-time
          description: RFC3339 UTC end of the range
          example: "2024-01-02T00:00:00.000Z"
        - in: query
          name: resources
          required: false
          schema:
            type: string
          description: >-
            Lazy selector: comma-separated list of the metric blocks to return
            (cpu, ram, storage, bandwidth, power, telemetry, powerUsage). Only the
            requested blocks are fetched; empty returns the default set.
        - in: query
          name: mode
          required: false
          schema:
            type: string
          description: >-
            Colocation and baremetal. Series layout for the folded telemetry block
            (aggregate | split; defaults to aggregate). Ignored for vps.
        - in: query
          name: p95
          required: false
          schema:
            type: boolean
          description: >-
            Colocation and baremetal. When true, the folded telemetry block includes
            the billing p95 row. Ignored for vps.
        - in: query
          name: window
          required: false
          schema:
            type: string
          description: >-
            Colocation only. Aggregation window for the folded power-usage block
            (defaults to 7d). Ignored for vps/baremetal.
      responses:
        "200":
          description: >-
            A JSON response with metric series. Each array is omitted entirely
            when empty.
          content:
            application/json:
              schema:
                type: object
                properties:
                  cpu:
                    type: array
                    items:
                      type: object
                      properties:
                        date:
                          type: string
                        utilization:
                          type: number
                  ram:
                    type: array
                    items:
                      type: object
                      properties:
                        date:
                          type: string
                        utilization:
                          type: number
                  bandwidth:
                    type: array
                    items:
                      type: object
                      properties:
                        date:
                          type: string
                        input:
                          type: number
                        output:
                          type: number
                  storage:
                    type: array
                    items:
                      type: object
                      properties:
                        date:
                          type: string
                        read:
                          type: number
                        write:
                          type: number
                  power:
                    type: array
                    description: >-
                      Electrical draw in watts (colocation only, best-effort;
                      may be empty).
                    items:
                      type: object
                      properties:
                        date:
                          type: string
                        watts:
                          type: number
                  telemetry:
                    type: object
                    description: >-
                      Colocation & baremetal. Folded telemetry block (period totals,
                      billing p95, series) — same shape as the deprecated
                      GET .../telemetry. Present when requested via
                      resources=telemetry.
                  powerUsage:
                    type: object
                    description: >-
                      Colocation only. Folded power-usage block (usage fraction,
                      per-device breakdown). Present when requested via
                      resources=powerUsage.
        "404":
          description: Invalid path param or unparseable start/stop timestamp (empty body)
        "500":
          description: Internal Server Error
  /v1/query/profiles/{profileId}/services/{serviceId}/usage/transfer:
    get:
      tags:
        - query
      summary: Get transfer usage for the current billing period
      parameters:
        - in: path
          name: profileId
          required: true
          schema:
            type: number
          description: specify the profile id
          example: 1
        - in: path
          name: serviceId
          required: true
          schema:
            type: number
          description: specify the service id
          example: 427
      responses:
        "200":
          description: A JSON response with the transfer usage in bytes
          content:
            application/json:
              schema:
                type: object
                properties:
                  usage_bytes:
                    type: number
                    example: 1099511627776
        "404":
          description: No usage collected yet for the current billing period (empty body)
        "500":
          description: Internal Server Error
  /v1/query/profiles/{profileId}/services/{serviceId}/operating-systems:
    get:
      tags:
        - query
      summary: Get available operating systems for reinstall
      parameters:
        - in: path
          name: profileId
          required: true
          schema:
            type: number
          description: specify the profile id
          example: 1
        - in: path
          name: serviceId
          required: true
          schema:
            type: number
          description: specify the service id
          example: 427
      responses:
        "200":
          description: A JSON response with the available and current operating systems
          content:
            application/json:
              schema:
                type: object
                properties:
                  current:
                    type: object
                    description: Zero-valued ({id:0, name:""}) when none
                    properties:
                      id:
                        type: integer
                        example: 12
                      name:
                        type: string
                        example: CentOS 8
                  available:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: integer
                          example: 12
                        name:
                          type: string
                          example: CentOS 8
        "400":
          description: Invalid serviceId parameter
        "500":
          description: Internal Server Error
  /v1/query/profiles/{profileId}/services/{serviceId}/installation/monitoring:
    get:
      tags:
        - query
      summary: Get OS installation/reinstall progress
      parameters:
        - in: path
          name: profileId
          required: true
          schema:
            type: number
          description: specify the profile id
          example: 1
        - in: path
          name: serviceId
          required: true
          schema:
            type: number
          description: specify the service id
          example: 427
      responses:
        "200":
          description: A JSON response with the installation progress
          content:
            application/json:
              schema:
                type: object
                properties:
                  isInstalling:
                    type: boolean
                    example: true
                  isCancellation:
                    type: boolean
                    example: false
                  progress:
                    type: object
                    nullable: true
                    description: null when there is no progress yet
                    properties:
                      completedSteps:
                        type: integer
                        example: 2
                      totalSteps:
                        type: integer
                        example: 5
                      currentStep:
                        type: string
                        example: partitioning
                      overallStatus:
                        type: string
                        example: running
                      startDate:
                        type: string
                      endDate:
                        type: string
                      steps:
                        type: array
                        items:
                          type: object
                          properties:
                            step:
                              type: integer
                              example: 2
                            name:
                              type: string
                              example: Download image
                            status:
                              type: string
                              example: done
                  switchingFrom:
                    type: string
                    example: CentOS 8
                  switchingTo:
                    type: string
                    example: Ubuntu 22.04
        "400":
          description: Invalid serviceId parameter
        "500":
          description: Internal Server Error
  /v1/query/profiles/{profileId}/services/{serviceId}/upgrades/pending:
    get:
      tags:
        - query
      summary: Get pending OS upgrades for a service
      parameters:
        - in: path
          name: profileId
          required: true
          schema:
            type: number
          description: specify the profile id
          example: 1
        - in: path
          name: serviceId
          required: true
          schema:
            type: number
          description: specify the service id
          example: 427
      responses:
        "200":
          description: A JSON array of pending upgrades (empty when none)
          content:
            application/json:
              schema:
                type: array
                items:
                  type: object
                  properties:
                    operatingSystem:
                      type: string
                      example: CentOS 8
                    newOperatingSystem:
                      type: string
                      example: Windows Server 2022
                    status:
                      type: string
                      example: Pending
                    invoiceId:
                      type: integer
                      example: 10021
        "400":
          description: Invalid serviceId parameter
        "500":
          description: Internal Server Error

  /v1/query/profiles/{profileId}/services/{serviceId}/history:
    get:
      tags:
        - query
      summary: Service change feed / history (colocation & baremetal)
      parameters:
        - in: path
          name: profileId
          required: true
          schema:
            type: number
          description: specify the profile id
          example: 1
        - in: path
          name: serviceId
          required: true
          schema:
            type: number
          description: specify the service id
          example: 427
        - in: query
          name: kind
          required: false
          schema:
            type: string
          description: Filter history by event type; empty/all keeps every type
        - in: query
          name: limit
          required: false
          schema:
            type: number
          description: Page size (baremetal); omitted/0 returns the whole set from the cursor
        - in: query
          name: cursor
          required: false
          schema:
            type: string
          description: Opaque cursor from a previous response's nextCursor
      responses:
        "200":
          description: History events; baremetal paginated via limit/cursor with total
        "400":
          description: Invalid path or query parameter
        "401":
          description: Unauthorized
        "404":
          description: Not found
        "500":
          description: Internal Server Error
  /v1/query/profiles/{profileId}/services/{serviceId}/macs:
    get:
      tags:
        - query
      summary: MACs seen on the service ports (colocation & baremetal)
      parameters:
        - in: path
          name: profileId
          required: true
          schema:
            type: number
          description: specify the profile id
          example: 1
        - in: path
          name: serviceId
          required: true
          schema:
            type: number
          description: specify the service id
          example: 427
        - in: query
          name: includeHistory
          required: false
          schema:
            type: boolean
          description: Include historical (not-current) rows
        - in: query
          name: limit
          required: false
          schema:
            type: integer
          description: Page size (baremetal); omitted/0 returns the whole set from the cursor
        - in: query
          name: cursor
          required: false
          schema:
            type: string
          description: Opaque cursor from a previous response's nextCursor
      responses:
        "200":
          description: MAC list; baremetal paginated via limit/cursor with total
        "400":
          description: Invalid path or query parameter
        "401":
          description: Unauthorized
        "404":
          description: Not found
        "500":
          description: Internal Server Error
  /v1/query/profiles/{profileId}/services/{serviceId}/components:
    get:
      tags:
        - query
      summary: Physical components of a colocation/baremetal service
      parameters:
        - in: path
          name: profileId
          required: true
          schema:
            type: number
          description: specify the profile id
          example: 1
        - in: path
          name: serviceId
          required: true
          schema:
            type: number
          description: specify the service id
          example: 427
        - in: query
          name: type
          required: false
          schema:
            type: string
          description: Filter components by type
        - in: query
          name: role
          required: false
          schema:
            type: string
          description: Filter components by role
        - in: query
          name: currentOnly
          required: false
          schema:
            type: boolean
          description: Only currently-attached components
      responses:
        "200":
          description: Component inventory (servers, switch ports, PDU outlets, chassis)
        "400":
          description: Invalid path or query parameter
        "401":
          description: Unauthorized
        "404":
          description: Not found
        "500":
          description: Internal Server Error
  /v1/query/profiles/{profileId}/services/{serviceId}/switch-ports:
    get:
      tags:
        - query
      summary: Switch ports of a baremetal service
      parameters:
        - in: path
          name: profileId
          required: true
          schema:
            type: number
          description: specify the profile id
          example: 1
        - in: path
          name: serviceId
          required: true
          schema:
            type: number
          description: specify the service id
          example: 427
      responses:
        "200":
          description: Switch port list
        "400":
          description: Invalid path or query parameter
        "401":
          description: Unauthorized
        "404":
          description: Not found
        "500":
          description: Internal Server Error
  /v1/query/profiles/{profileId}/services/{serviceId}/racks:
    get:
      tags:
        - query
      summary: Colocation rack elevations
      parameters:
        - in: path
          name: profileId
          required: true
          schema:
            type: number
          description: specify the profile id
          example: 1
        - in: path
          name: serviceId
          required: true
          schema:
            type: number
          description: specify the service id
          example: 427
      responses:
        "200":
          description: Rack elevations with anonymised neighbour spans (colocation only; 404 otherwise)
        "400":
          description: Invalid path or query parameter
        "401":
          description: Unauthorized
        "404":
          description: Not found
        "500":
          description: Internal Server Error
  /v1/query/profiles/{profileId}/services/{serviceId}/credentials/reveal:
    post:
      tags:
        - query
      summary: Reveal the service username and password (audited, no-store)
      parameters:
        - in: path
          name: profileId
          required: true
          schema:
            type: number
          description: specify the profile id
          example: 1
        - in: path
          name: serviceId
          required: true
          schema:
            type: number
          description: specify the service id
          example: 427
      responses:
        "200":
          description: Credentials { username, password }
        "401":
          description: Unauthorized
        "403":
          description: Forbidden
        "404":
          description: Not found
        "500":
          description: Internal Server Error
  /v1/webhosting/{serviceId}/firewall:
    get:
      tags:
        - webhosting
      summary: Search an IP in the service firewall
      parameters:
        - in: path
          name: serviceId
          required: true
          schema:
            type: number
          description: specify the service id
          example: 427
        - in: query
          name: ip
          required: true
          schema:
            type: string
          description: IP address to search
          example: 203.0.113.10
      responses:
        "200":
          description: Firewall match for the IP
        "400":
          description: Invalid path or query parameter
        "401":
          description: Unauthorized
        "403":
          description: Forbidden
        "500":
          description: Internal Server Error
  /v1/webhosting/{serviceId}/firewall/unlock:
    post:
      tags:
        - webhosting
      summary: Unlock an IP in the service firewall
      parameters:
        - in: path
          name: serviceId
          required: true
          schema:
            type: number
          description: specify the service id
          example: 427
      responses:
        "200":
          description: IP unlocked
        "400":
          description: Invalid path or query parameter
        "401":
          description: Unauthorized
        "403":
          description: Forbidden
        "500":
          description: Internal Server Error
