{
  "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": "Production (v1)"
    },
    {
      "url": "https://sandbox.api.boyahq.com/v1",
      "description": "Sandbox (v1)"
    }
  ],
  "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/transfers/status": {
      "get": {
        "summary": "Get employee allocation/deduction transfer status",
        "parameters": [
          {
            "in": "query",
            "name": "reference",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Reference of allocation or deduction"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TransferFundsStatus"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/employees/{employee_id}": {
      "get": {
        "summary": "Get a specific employee profile and balance",
        "parameters": [
          {
            "in": "path",
            "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",
        "required": [
          "accountref",
          "amount",
          "description",
          "employee_id"
        ],
        "properties": {
          "accountref": {
            "type": "integer",
            "description": "org_wallet_ref",
            "default": 1
          },
          "amount": {
            "type": "integer"
          },
          "description": {
            "type": "string"
          },
          "employee_id": {
            "type": "string"
          }
        }
      },
      "TransferFundsStatus": {
        "type": "object",
        "required": [
          "amount",
          "description",
          "employee_id"
        ],
        "properties": {
          "amount": {
            "type": "number"
          },
          "description": {
            "type": "string"
          },
          "employee_id": {
            "type": "string"
          },
          "reference": {
            "type": "string"
          },
          "status": {
            "type": "string"
          }
        }
      },
      "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": "number",
            "format": "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"
          },
          "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"
          }
        }
      }
    },
    "parameters": {
      "pageParam": {
        "in": "query",
        "name": "page",
        "required": false,
        "description": "Page number (1-based).",
        "schema": {
          "type": "integer",
          "default": 1,
          "minimum": 1
        }
      },
      "limitParam": {
        "in": "query",
        "name": "limit",
        "required": false,
        "description": "Number of items per page.",
        "schema": {
          "type": "integer",
          "default": 50,
          "minimum": 1
        }
      }
    },
    "responses": {
      "BadRequest": {
        "description": "Bad request — the request was malformed or invalid.",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "errorMessage": {
                  "type": "string",
                  "example": "Invalid request parameters"
                }
              }
            }
          }
        }
      },
      "Unauthorized": {
        "description": "Unauthorized — missing or invalid API key.",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "errorMessage": {
                  "type": "string",
                  "example": "Unauthorized"
                }
              }
            }
          }
        }
      },
      "NotFound": {
        "description": "Not found — the requested resource does not exist.",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "errorMessage": {
                  "type": "string",
                  "example": "Resource not found"
                }
              }
            }
          }
        }
      }
    }
  },
  "security": [
    {
      "ApiKeyAuth": []
    }
  ]
}