openapi: 3.0.3
info:
  title: Auth API 6lai Public Integration API
  version: 1.0.0
  description: Public endpoints only
servers:
  - url: /
paths:
  /api/v1/verify:
    post:
      tags: [Verify]
      summary: Verify license and check upgrade eligibility
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/VerifyRequest'
      responses:
        '200':
          description: Business response envelope (success or failed validation)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BaseResponse'
              examples:
                success:
                  summary: Success example
                  value:
                    status: 1
                    msg: ok
                    data:
                      allow_upgrade: 1
                      latest_version: 1.2.3
                      download_url: https://example.com/release/1.2.3
                invalid_request:
                  summary: Invalid request example
                  value:
                    status: 0
                    msg: invalid request
                    data: null
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BaseResponse'
              examples:
                internal_error:
                  summary: Internal error example
                  value:
                    status: 0
                    msg: internal server error
                    data: null
  /api/v1/release/latest:
    post:
      tags: [Release]
      summary: Query latest release for tenant/channel
      security:
        - bearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/LatestReleaseRequest'
      responses:
        '200':
          description: Query latest release result
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BaseResponse'
  /api/v1/agent/register:
    post:
      tags: [Agent]
      summary: Register agent and issue short-lived token
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AgentRegisterRequest'
      responses:
        '200':
          description: Agent register result
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BaseResponse'
  /api/v1/agent/poll:
    post:
      tags: [Agent]
      summary: Poll pending task for agent
      security:
        - bearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AgentPollRequest'
      responses:
        '200':
          description: Poll task result
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BaseResponse'
  /api/v1/agent/report:
    post:
      tags: [Agent]
      summary: Report task stage/state/progress
      security:
        - bearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AgentReportRequest'
      responses:
        '200':
          description: Report task result
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BaseResponse'
  /api/v1/agent/heartbeat:
    post:
      tags: [Agent]
      summary: Agent heartbeat keepalive
      security:
        - bearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AgentHeartbeatRequest'
      responses:
        '200':
          description: Heartbeat result
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BaseResponse'
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
  schemas:
    VerifyRequest:
      type: object
      required:
        - project_code
        - license_id
        - domain
        - server_ip
        - machine_fingerprint
        - current_version
        - action
        - timestamp
        - nonce
        - sign
      properties:
        project_code:
          type: string
        license_id:
          type: string
        domain:
          type: string
        server_ip:
          type: string
        machine_fingerprint:
          type: string
        current_version:
          type: string
        action:
          type: string
          enum: [check, upgrade]
        timestamp:
          type: integer
          format: int64
        nonce:
          type: string
        sign:
          type: string
    BaseResponse:
      type: object
      properties:
        status:
          type: integer
          description: 1 means success, 0 means failure
          example: 1
        msg:
          type: string
          example: ok
        data:
          nullable: true
          type: object
    LatestReleaseRequest:
      type: object
      required:
        - tenant_id
        - timestamp
        - nonce
        - sign
      properties:
        tenant_id:
          type: string
        channel:
          type: string
        current_version:
          type: string
        timestamp:
          type: integer
          format: int64
        nonce:
          type: string
        sign:
          type: string
    AgentRegisterRequest:
      type: object
      required:
        - tenant_id
        - agent_id
        - license_id
        - domain
        - machine_fingerprint
        - channel
        - timestamp
        - nonce
        - sign
      properties:
        tenant_id:
          type: string
        agent_id:
          type: string
        license_id:
          type: string
        domain:
          type: string
        machine_fingerprint:
          type: string
        channel:
          type: string
        timestamp:
          type: integer
          format: int64
        nonce:
          type: string
        sign:
          type: string
    AgentPollRequest:
      type: object
      required:
        - tenant_id
        - agent_id
        - channel
        - timestamp
        - nonce
        - sign
      properties:
        tenant_id:
          type: string
        agent_id:
          type: string
        channel:
          type: string
        timestamp:
          type: integer
          format: int64
        nonce:
          type: string
        sign:
          type: string
    AgentReportRequest:
      type: object
      required:
        - task_id
        - stage
        - state
        - timestamp
        - nonce
        - sign
      properties:
        task_id:
          type: string
        stage:
          type: string
        state:
          type: string
        progress:
          type: integer
          minimum: 0
          maximum: 100
        message:
          type: string
        error_reason:
          type: string
        payload:
          type: object
          nullable: true
        timestamp:
          type: integer
          format: int64
        nonce:
          type: string
        sign:
          type: string
    AgentHeartbeatRequest:
      type: object
      required:
        - timestamp
        - nonce
        - sign
      properties:
        timestamp:
          type: integer
          format: int64
        nonce:
          type: string
        sign:
          type: string
