openapi: 3.1.0
info:
  title: Teams API
  version: '1.0'
  description: API for managing teams within the organization
servers:
  - url: https://api.boyahq.com/v1
    description: Boya API server
security:
  - ApiKeyAuth: []
paths:
  /teams:
    get:
      summary: Get all teams
      parameters:
        - in: header
          name: org_wallet_ref
          required: true
          default: '1'
          schema:
            type: string
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Team'
    post:
      summary: Create a new team
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TeamInput'
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Team'
  /teams/{teamId}:
    get:
      summary: Get a specific team
      parameters:
        - name: teamId
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Team'
    patch:
      summary: Update a team
      parameters:
        - name: teamId
          in: path
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TeamUpdate'
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Team'
    delete:
      summary: Delete a team
      parameters:
        - name: teamId
          in: path
          required: true
          schema:
            type: string
      responses:
        '204':
          description: Successful response
  /teams/{teamId}/reviewers:
    post:
      summary: Add a reviewer to a team
      parameters:
        - name: teamId
          in: path
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ReviewerInput'
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Reviewer'
  /teams/{teamId}/reviewers/{reviewerId}:
    patch:
      summary: Remove a reviewer from a team
      parameters:
        - name: teamId
          in: path
          required: true
          schema:
            type: string
        - name: reviewerId
          in: path
          required: true
          schema:
            type: string
      responses:
        '204':
          description: Successful response
  /teams/addEmployee/:
    post:
      summary: Move employee to a team
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/MoveEmployeeInput'
      responses:
        '201':
          description: Employee Moved to Team
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Employee'
components:
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-API-KEY
  schemas:
    Team:
      type: object
      properties:
        _id:
          type: string
        name:
          type: string
        status:
          type: string
        reviewers:
          type: array
          items:
            $ref: '#/components/schemas/Reviewer'
        code:
          type: string
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
        __v:
          type: number
        updated_by:
          type: string
        employee_count:
          type: number
        employees:
          type: array
          items:
            $ref: '#/components/schemas/Employee'
        balance:
          type: number
    Reviewer:
      type: object
      properties:
        employee_id:
          type: string
        name:
          type: string
        read_only:
          type: boolean
        _id:
          type: string
        added_on:
          type: string
          format: date-time
    Employee:
      type: object
      properties:
        name:
          type: string
        phone:
          type: string
        organization_email:
          type: string
        employee_id:
          type: string
        role:
          type: string
          enum:
            - CARD USER
            - REVIEWER
            - APPROVER
        team_code:
          type: string
        key:
          type: string
        balance:
          type: number
    TeamInput:
      type: object
      required:
        - name
        - code
      properties:
        name:
          type: string
        code:
          type: string
        status:
          type: string
          default: ACTIVE
    TeamUpdate:
      type: object
      properties:
        name:
          type: string
        status:
          type: string
    ReviewerInput:
      type: object
      required:
        - employee_id
        - name
      properties:
        employee_id:
          type: string
        name:
          type: string
        read_only:
          type: boolean
          default: false
    EmployeeInput:
      type: object
      required:
        - name
        - phone
        - organization_email
        - role
      properties:
        name:
          type: string
        phone:
          type: string
        organization_email:
          type: string
        role:
          type: string
          enum:
            - CARD USER
            - REVIEWER
            - APPROVER
    MoveEmployeeInput:
      type: object
      required:
        - team_code
        - employee_id
      properties:
        team_code:
          type: string
        employee_id:
          type: string
