{
  "openapi": "3.1.0",
  "info": {
    "title": "Categories / Chart of Accounts API",
    "version": "1.0",
    "description": "API for managing categories and subcategories (chart of accounts)."
  },
  "servers": [
    {
      "url": "https://api.boyahq.com/v1",
      "description": "Production (v1)"
    },
    {
      "url": "https://sandbox.api.boyahq.com/v1",
      "description": "Sandbox (v1)"
    }
  ],
  "security": [
    {
      "ApiKeyAuth": []
    }
  ],
  "paths": {
    "/categories": {
      "get": {
        "summary": "List categories",
        "description": "Fetch all categories (chart of accounts) for the business.",
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Category"
                  }
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Create a new category",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CategoryInput"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Category"
                }
              }
            }
          }
        }
      }
    },
    "/categories/{categoryId}": {
      "patch": {
        "summary": "Update a category",
        "parameters": [
          {
            "name": "categoryId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CategoryUpdate"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Category"
                }
              }
            }
          }
        }
      },
      "delete": {
        "summary": "Archive a category",
        "parameters": [
          {
            "name": "categoryId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Category archived",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ArchiveResult"
                }
              }
            }
          }
        }
      }
    },
    "/categories/{categoryId}/subcategories": {
      "post": {
        "summary": "Create a subcategory",
        "parameters": [
          {
            "name": "categoryId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SubcategoryInput"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Subcategory"
                }
              }
            }
          }
        }
      }
    },
    "/categories/{categoryId}/subcategories/{subcategoryId}": {
      "patch": {
        "summary": "Update a subcategory",
        "parameters": [
          {
            "name": "categoryId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "subcategoryId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SubcategoryUpdate"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Subcategory"
                }
              }
            }
          }
        }
      },
      "delete": {
        "summary": "Archive a subcategory",
        "parameters": [
          {
            "name": "categoryId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "subcategoryId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Subcategory archived",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ArchiveResult"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-KEY"
      }
    },
    "schemas": {
      "Category": {
        "type": "object",
        "properties": {
          "_id": {
            "type": "string"
          },
          "groupid": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "example": "ACTIVE"
          },
          "subcategories": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Subcategory"
            }
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          },
          "__v": {
            "type": "number"
          }
        }
      },
      "Subcategory": {
        "type": "object",
        "properties": {
          "_id": {
            "type": "string"
          },
          "group_id": {
            "type": "string"
          },
          "category": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "example": "ACTIVE"
          },
          "teams": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "mapping_id": {
            "type": "string"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          },
          "__v": {
            "type": "number"
          }
        }
      },
      "CategoryInput": {
        "type": "object",
        "required": [
          "name"
        ],
        "properties": {
          "name": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "default": "ACTIVE"
          }
        }
      },
      "CategoryUpdate": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "status": {
            "type": "string"
          }
        }
      },
      "SubcategoryInput": {
        "type": "object",
        "required": [
          "name"
        ],
        "properties": {
          "name": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "default": "ACTIVE"
          }
        }
      },
      "SubcategoryUpdate": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "status": {
            "type": "string"
          }
        }
      },
      "ArchiveResult": {
        "type": "object",
        "properties": {
          "message": {
            "type": "string",
            "example": "Category archived successfully"
          },
          "status": {
            "type": "string",
            "example": "ARCHIVED"
          }
        }
      }
    }
  }
}