openapi: 3.0.0
info:
  title: Authentication
  description: APIs to authenticate admin
  version: 1.0.0
components:
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
  
# sigin api
paths:
  /api/admin/signin:
    post:
      summary: Authenticate admin and return access_token and refresh_token
      description: >-
        Authenticate user with given credentials and return access_token and
        refresh_token in response.
      tags: ["Admin Authentication"]
      requestBody:
        description: JSON object containing username and password
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                username:
                  type: string
                  example: john.doe
                password:
                  type: string
                  example: password123
              required:
                - username
                - password
      responses:
        "200":
          description: Successful response containing access_token and refresh_token
          content:
            application/json:
              schema:
                type: object
                properties:
                  access_token:
                    type: string
                    example: >-
                      eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJpYXQiOjE2MjU2MzQ2MjIsImV4cCI6MTYyNTYzODIyMn0.cw_wzroU98q3N8zKhhD9rGQypFBDZfA8xb6CFkbUx7w
                  refresh_token:
                    type: string
                    example: >-
                      eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJpYXQiOjE2MjU2MzQ2MjIsImV4cCI6MTYyNzIzODIyMn0.rMf_tzwwdtlmRmpKZT3TqjrUMAcrX9SBJAaSKyRxtKs
                required:
                  - access_token
                  - refresh_token
        "400":
          description: Bad request error message
        "401":
          description: Unauthorized error message
        "500":
          description: Internal Server Error

  # refresh api
  /api/admin/refresh:
    post:
      summary: Verify the refresh_token and returns new access_token and refresh_token
      description: >-
        This api verifies the refresh_token and returns new access_token and new refresh_token
      tags: ["Admin Authentication"]
      requestBody:
        description: JSON object containing valid refresh_token
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                refresh_token:
                  type: string
                  example: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoyLCJ1c2VybmFtZSI6InJhcGF0aWNvbGxlY3Rpb24iLCJ1c2VyX3R5cGUiOiJmYXJtZXIiLCJsZWRnZXJfaWQiOjg0LCJpYXQiOjE2NzY4Nzk5NzcsImV4cCI6MTY3Njg4MDI3N30.KXJ3_-VImWCPHIQyICklVmzZCYTg3PQYAg8OqH9flqE
              required:
                - refresh_token
      responses:
        "200":
          description: Successful response containing new access_token and refresh_token
          content:
            application/json:
              schema:
                type: object
                properties:
                  access_token:
                    type: string
                    example: >-
                      eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJpYXQiOjE2MjU2MzQ2MjIsImV4cCI6MTYyNTYzODIyMn0.cw_wzroU98q3N8zKhhD9rGQypFBDZfA8xb6CFkbUx7w
                  refresh_token:
                    type: string
                    example: >-
                      eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJpYXQiOjE2MjU2MzQ2MjIsImV4cCI6MTYyNzIzODIyMn0.rMf_tzwwdtlmRmpKZT3TqjrUMAcrX9SBJAaSKyRxtKs
                required:
                  - access_token
                  - refresh_token
        "400":
          description: Bad request error message
        "401":
          description: Unauthorized error message
        "500":
          description: Internal Server Error

  # logout api
  /api/admin/logout:
    post:
      summary: Logs out the admin
      description: >-
        This api verifies the refresh_token and revokes the refresh_token from the database
      tags: ["Admin Authentication"]
      security:
        - BearerAuth: []
      requestBody:
        description: JSON object containing valid refresh_token
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                refresh_token:
                  type: string
                  example: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoyLCJ1c2VybmFtZSI6InJhcGF0aWNvbGxlY3Rpb24iLCJ1c2VyX3R5cGUiOiJmYXJtZXIiLCJsZWRnZXJfaWQiOjg0LCJpYXQiOjE2NzY4Nzk5NzcsImV4cCI6MTY3Njg4MDI3N30.KXJ3_-VImWCPHIQyICklVmzZCYTg3PQYAg8OqH9flqE
              required:
                - refresh_token
      responses:
        "200":
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: boolean
                    example: >-
                      true
                  message:
                    type: string
                    example: >-
                      Logged out successfully!!!
                required:
                  - status
                  - message
        "400":
          description: Bad request error message
        "401":
          description: Unauthorized error message
        "500":
          description: Internal Server Error

  # reset password api
  /api/admin/reset-password:
    post:
      summary: resets the password
      description: >-
        This api verifies the old password and update it with new password in the database
      tags: ["Admin Authentication"]
      security:
        - BearerAuth: []
      requestBody:
        description: JSON object containing old password and new password
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                oldPassword:
                  type: string
                  example: abcde12345
                newPassword:
                  type: string
                  example: abcde98765
              required:
                - oldPassword
                - newPassword
      responses:
        "200":
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: boolean
                    example: >-
                      true
                  message:
                    type: string
                    example: >-
                      Password updated successfully!!!
                required:
                  - status
                  - message
        "400":
          description: Bad request error message
        "401":
          description: Unauthorized error message
        "500":
          description: Internal Server Error

  /api/payment/payment_count_by_user:
    get:
      summary: Returns the total user count, total paid user count, and total unpaid user count 
      description: >-
        Will return total user count, paid user count (user who paid for question sets or package set) and unpaid user count
      tags: ["Admin Home Page"]
      responses:
        "200":
          description: Successful response containing total_user_count, total_paid_users and total_unpaid_users
          content:
            application/json:
              schema:
                type: object
                properties:
                  total_user_count:
                    type: number
                    example: >-
                      8
                  total_paid_users:
                    type: number
                    example: >-
                      8
                  total_unpaid_users:
                    type: number
                    example: >-
                      8
                required:
                  - total_user_count
                  - total_paid_users
                  - total_unpaid_users
        "400":
          description: Bad request error message
        "401":
          description: Unauthorized error message
        "500":
          description: Internal Server Error
