openapi: 3.0.0
info:
  title: Boya Employees API
  version: 1.0.0
  description: API for managing employees in the Boya platform
servers:
  - url: https://api.boyahq.com/v1
    description: Boya API server
paths:
  /employees:
    get:
      summary: List all employees
      parameters:
        - $ref: '#/components/parameters/pageParam'
        - $ref: '#/components/parameters/limitParam'
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Employee'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
    post:
      summary: Create a new employee
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/EmployeeInput'
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Employee'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
  /employees/suspend:
    delete:
      summary: Suspend an employee
      parameters:
        - in: query
          name: employee_id
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Employee suspended successfully
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
  /employees/activate:
    patch:
      summary: Activate an employee
      parameters:
        - in: query
          name: employee_id
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Employee activated successfully
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
  /employees/addMoney:
    post:
      summary: Add money to an employee wallet
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TransferFunds'
      responses:
        '200':
          description: Allocation successful
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
  /employees/deductMoney:
    post:
      summary: Deduct money from employee wallet
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TransferFunds'
      responses:
        '200':
          description: Deduction successful
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
  /employees/?employee_id={employee_id}:
    get:
      summary: Get a specific employee profile and balance
      parameters:
        - in: query
          name: employee_id
          required: true
          schema:
            type: integer
        - in: query
          name: org_wallet_ref
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Employee'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
  /employees/balances:
    get:
      summary: Get All employee balances - add a specified date range
      parameters:
        - in: query
          name: from
          required: true
          schema:
            type: string
            format: date-time
          description: Start date and time for the balance period
        - in: query
          name: to
          required: true
          schema:
            type: string
            format: date-time
          description: End date and time for the balance period YYYY-MM-DD HH:MM:SS
        - $ref: '#/components/parameters/pageParam'
        - $ref: '#/components/parameters/limitParam'
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EmployeeBalancesResponse'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
components:
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-API-KEY
  schemas:
    TransferFunds:
      type: object
      properties:
        accountref:
          type: integer
          description: org_wallet_ref
          required: true
          default: 1
        amount:
          type: integer
          required: true
        description:
          type: string
          required: true
        employee_id:
          type: string
          required: true
    Employee:
      type: object
      properties:
        id:
          type: string
        name:
          type: string
        phone:
          type: string
        team_code:
          type: string
        organization_email:
          type: string
        role:
          type: string
        accno:
          type: string
          description: employee wallet accno
        balance:
          type: double
          description: account balance
        status:
          type: string
          enum:
            - ACTIVE
            - SUSPENDED
        createdAt:
          type: string
          format: date
    EmployeeInput:
      type: object
      required:
        - name
        - organization_email
        - phone_number
        - team_code
        - role
      properties:
        name:
          type: string
        organization_email:
          type: string
        phone_number:
          type: string
        team_code:
          type: string
          required: true
        role:
          type: string
          enum:
            - CARD USER
    EmployeeBalancesResponse:
      type: object
      properties:
        openingEmployeeWalletsTotal:
          type: number
        closingEmployeeWalletsTotal:
          type: number
        employees:
          type: object
          properties:
            docs:
              type: array
              items:
                $ref: '#/components/schemas/EmployeeBalance'
            total:
              type: integer
            limit:
              type: string
            page:
              type: string
            pages:
              type: integer
    EmployeeBalance:
      type: object
      properties:
        _id:
          type: string
        name:
          type: string
        employee_id:
          type: string
        accno:
          type: string
        invited_on:
          type: string
          format: date-time
        organization_email:
          type: string
        phone:
          type: string
        status:
          type: string
        role:
          type: string
        id:
          type: string
        openingBalance:
          type: string
        closingBalance:
          type: string
        teamName:
          type: string
        teamOID:
          type: string
    Error:
      type: object
      properties:
        code:
          type: integer
        message:
          type: string
  parameters:
    pageParam:
      in: query
      name: page
      schema:
        type: integer
        default: 1
      description: Page number for pagination
    limitParam:
      in: query
      name: limit
      schema:
        type: integer
        default: 50
      description: Number of items per page
  responses:
    BadRequest:
      description: Bad request
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Unauthorized:
      description: Unauthorized
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    NotFound:
      description: Resource not found
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
security:
  - ApiKeyAuth: []
