openapi: 3.0.1
info:
  title: OQTOPUS Cloud User API
  version: '1.0'
  contact:
    name: oqtopus-team
    email: oqtopus-team[at]googlegroups.com
  description: OQTOPUS Cloud User API. This API is used to interact with the OQTOPUS Cloud service. The API provides endpoints to manage devices, jobs, and results.
  license:
    name: Apache 2.0
    url: https://www.apache.org/licenses/LICENSE-2.0.html
servers:
  - url: http://localhost:8080
    description: Local server url
paths:
  /signup:
    post:
      tags:
        - signup
      summary: Signup
      description: Signup a new user
      operationId: signup
      security:
        - BearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/signup.SignupRequest'
      responses:
        '201':
          description: Signup successful
        '400':
          description: Signup failed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/error.BadRequest'
        '401':
          description: Unauthorized
        '403':
          description: Not authorized
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/error.InternalServerError'
  /confirm:
    put:
      tags:
        - signup
      summary: Confirm signup
      description: Confirm a new user
      operationId: confirm_signup
      security:
        - BearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/confirm_signup.ConfirmationSignupRequest'
      responses:
        '200':
          description: Confirmation successful
        '400':
          description: Confirmation failed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/error.BadRequest'
        '401':
          description: Unauthorized
        '403':
          description: Not authorized
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/error.InternalServerError'
  /mfa_reset_request:
    put:
      tags:
        - signup
      summary: MFA Reset Request
      description: Request to reset MFA
      operationId: request_to_reset_mfa
      security:
        - BearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/mfa_reset_request.MfaResetRequest'
      responses:
        '200':
          description: MFA reset successful
        '400':
          description: MFA reset failed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/error.BadRequest'
        '401':
          description: Unauthorized
        '403':
          description: Not authorized
        '404':
          description: User not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/error.NotFoundError'
              example:
                message: User not found
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/error.InternalServerError'
  /mfa_reset/start:
    post:
      tags:
        - signup
      summary: Start MFA reset
      description: Send a verification code to the user's email for MFA reset.
      operationId: mfa_reset_start
      security:
        - BearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/mfa_reset.MfaResetStartRequest'
      responses:
        '200':
          description: Sent confirmation email successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/mfa_reset.MfaResetStartResponse'
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/error.BadRequest'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/error.InternalServerError'
  /mfa_reset/verify_code:
    post:
      tags:
        - signup
      summary: Verify MFA reset code
      description: Verify the code sent to the user's email for MFA reset.
      operationId: mfa_reset_verify_code
      security:
        - BearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/mfa_reset.MfaResetVerifyCodeRequest'
      responses:
        '204':
          description: Code verified
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/mfa_reset.MfaResetVerifyCodeResponse'
        '400':
          description: Verification failed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/error.BadRequest'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/error.InternalServerError'
  /mfa_reset/confirm_totp:
    post:
      tags:
        - signup
      summary: Confirm new TOTP for MFA
      description: Confirm and enable new TOTP MFA after verification.
      operationId: mfa_reset_confirm_totp
      security:
        - BearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/mfa_reset.MfaResetConfirmTotpRequest'
      responses:
        '204':
          description: MFA TOTP confirmed
        '400':
          description: Confirmation failed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/error.BadRequest'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/error.InternalServerError'
components:
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
  schemas:
    signup.SignupRequest:
      type: object
      properties:
        email:
          type: string
        password:
          type: string
      required:
        - email
        - password
    error.BadRequest:
      type: object
      properties:
        message:
          type: string
      required:
        - message
    error.InternalServerError:
      type: object
      properties:
        message:
          type: string
      required:
        - message
    confirm_signup.ConfirmationSignupRequest:
      type: object
      properties:
        email:
          type: string
          format: email
          description: The email address of the user
        confirmation_code:
          type: string
          description: The confirmation code sent to the user
      required:
        - email
        - confirmation_code
    mfa_reset_request.MfaResetRequest:
      type: object
      properties:
        email:
          type: string
          description: The email of the user
        password:
          type: string
          description: The password of the user
        client_id:
          type: string
          description: The client id of the user
      required:
        - email
        - password
        - client_id
    error.NotFoundError:
      type: object
      properties:
        message:
          type: string
      required:
        - message
    mfa_reset.MfaResetStartRequest:
      type: object
      required:
        - email
        - password
      properties:
        email:
          type: string
          format: email
        password:
          type: string
    mfa_reset.MfaResetStartResponse:
      type: object
      properties:
        access_token:
          type: string
          description: Access token to access Cognito API
    mfa_reset.MfaResetVerifyCodeRequest:
      type: object
      required:
        - access_token
        - code
      properties:
        access_token:
          type: string
        code:
          type: string
    mfa_reset.MfaResetVerifyCodeResponse:
      type: object
      properties:
        secret:
          type: string
          description: Base32 encoded secret for TOTP
    mfa_reset.MfaResetConfirmTotpRequest:
      type: object
      required:
        - access_token
        - totp_code
      properties:
        access_token:
          type: string
        totp_code:
          type: string
