{
  "openapi": "3.0.0",
  "info": {
    "title": "BizMate Backend API",
    "version": "1.0.0",
    "description": "API documentation for user authentication and profile management"
  },
  "tags": [
    {
      "name": "Auth",
      "description": "Authentication and user account management"
    },
    {
      "name": "User",
      "description": "User profile and settings"
    },
    {
      "name": "Dashboard",
      "description": "Provides summary reports, graphs, alerts, and reminders for the logged-in user."
    },
    {
      "name": "Stock Management",
      "description": "Manage categories, subcategories, stock items, transactions, and alerts"
    },
    {
      "name": "Customer Management",
      "description": "Customers, documents, credits and communications"
    },
    {
      "name": "Staff Management",
      "description": "Manage staff, attendance, payouts and performance"
    },
    {
      "name": "Finance Management",
      "description": "Income, Sales, Expenses, Loans and Investments (user-scoped)"
    }
  ],
  "paths": {
    "/api/auth/register": {
      "post": {
        "tags": [
          "Auth"
        ],
        "summary": "Create a new user account",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "example": "Usman Talib"
                  },
                  "email": {
                    "type": "string",
                    "example": "usmantalib202@gmail.com"
                  },
                  "password": {
                    "type": "string",
                    "example": "secret123"
                  },
                  "phone": {
                    "type": "string",
                    "example": "03001234567"
                  }
                },
                "required": [
                  "name",
                  "email",
                  "password",
                  "phone"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "User registered successfully"
          },
          "400": {
            "description": "Missing or invalid input"
          },
          "500": {
            "description": "Server error"
          }
        }
      }
    },
    "/api/auth/login": {
      "post": {
        "tags": [
          "Auth"
        ],
        "summary": "Login user",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "email": {
                    "type": "string",
                    "example": "usmantalib202@gmail.com"
                  },
                  "password": {
                    "type": "string",
                    "example": "secret123"
                  }
                },
                "required": [
                  "email",
                  "password"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Login successful"
          },
          "401": {
            "description": "Invalid credentials"
          }
        }
      }
    },
    "/api/auth/forgot-password": {
      "post": {
        "tags": [
          "Auth"
        ],
        "summary": "Request password reset token",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "email": {
                    "type": "string",
                    "example": "usmantalib202@gmail.com"
                  }
                },
                "required": [
                  "email"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Reset token generated"
          },
          "404": {
            "description": "Email not found"
          },
          "500": {
            "description": "Server error"
          }
        }
      }
    },
    "/api/auth/reset-password": {
      "post": {
        "tags": [
          "Auth"
        ],
        "summary": "Reset user password using token",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "example": "abc123xyz"
                  },
                  "newPassword": {
                    "type": "string",
                    "example": "newSecret123"
                  }
                },
                "required": [
                  "token",
                  "newPassword"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Password reset successful"
          },
          "400": {
            "description": "Invalid or expired token"
          },
          "500": {
            "description": "Server error"
          }
        }
      }
    },
    "/api/auth/change-password": {
      "put": {
        "tags": [
          "Auth"
        ],
        "summary": "Change password for logged-in user",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "currentPassword": {
                    "type": "string",
                    "example": "oldSecret123"
                  },
                  "newPassword": {
                    "type": "string",
                    "example": "newSecret456"
                  }
                },
                "required": [
                  "currentPassword",
                  "newPassword"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Password changed successfully",
            "content": {
              "application/json": {
                "example": {
                  "message": "Password changed successfully"
                }
              }
            }
          },
          "400": {
            "description": "Missing fields"
          },
          "401": {
            "description": "Incorrect current password or unauthorized"
          },
          "500": {
            "description": "Server error"
          }
        }
      }
    },
    "/api/auth/verify-otp": {
      "post": {
        "tags": [
          "Auth"
        ],
        "summary": "Verify OTP for login",
        "description": "Verifies the OTP sent to the user's email after login attempt. If valid, returns JWT token and user info.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "email": {
                    "type": "string",
                    "example": "usmantalib202@gmail.com"
                  },
                  "otp": {
                    "type": "string",
                    "example": "123456"
                  }
                },
                "required": [
                  "email",
                  "otp"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OTP verified, login successful",
            "content": {
              "application/json": {
                "example": {
                  "message": "OTP verified, login successful",
                  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
                  "user": {
                    "id": 1,
                    "email": "usmantalib202@gmail.com",
                    "name": "Usman Talib",
                    "role": "user"
                  }
                }
              }
            }
          },
          "400": {
            "description": "Missing email or OTP"
          },
          "401": {
            "description": "Invalid OTP or email"
          },
          "500": {
            "description": "Server error"
          }
        }
      }
    },
    "/api/auth/refresh-token": {
      "post": {
        "tags": [
          "Auth"
        ],
        "summary": "Generate new access token using refresh token",
        "description": "Requires a valid refresh token stored in HttpOnly cookie. Returns a new short-lived access token.",
        "responses": {
          "200": {
            "description": "New access token generated",
            "content": {
              "application/json": {
                "example": {
                  "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
                }
              }
            }
          },
          "401": {
            "description": "Missing refresh token"
          },
          "403": {
            "description": "Invalid or expired refresh token"
          },
          "500": {
            "description": "Server error"
          }
        }
      }
    },
    "/api/auth/logout": {
      "post": {
        "tags": [
          "Auth"
        ],
        "summary": "Logout user and clear refresh token",
        "description": "Deletes the refresh token from the database using the token provided in query parameter.",
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "example": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
            },
            "description": "The refresh token to be invalidated"
          }
        ],
        "responses": {
          "200": {
            "description": "User logged out successfully",
            "content": {
              "application/json": {
                "example": {
                  "message": "Logged out successfully"
                }
              }
            }
          },
          "400": {
            "description": "No refresh token provided in query"
          },
          "500": {
            "description": "Server error"
          }
        }
      }
    },
    "/api/auth/verify-email": {
      "post": {
        "tags": [
          "Auth"
        ],
        "summary": "Verify user email using token",
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "example": "abc123xyz"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Email verified successfully",
            "content": {
              "application/json": {
                "example": {
                  "message": "Email verified successfully"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or expired token"
          },
          "500": {
            "description": "Server error"
          }
        }
      }
    },
    "/api/auth/resend-verification": {
      "post": {
        "tags": [
          "Auth"
        ],
        "summary": "Resend email verification link",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "email": {
                    "type": "string",
                    "example": "user@example.com"
                  }
                },
                "required": [
                  "email"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Verification link resent",
            "content": {
              "application/json": {
                "example": {
                  "message": "Verification link resent to email"
                }
              }
            }
          },
          "400": {
            "description": "Missing or already verified email"
          },
          "404": {
            "description": "User not found"
          },
          "500": {
            "description": "Server or email error"
          }
        }
      }
    },
    "/api/users/me": {
      "get": {
        "tags": [
          "User"
        ],
        "summary": "Get logged-in user's profile",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "User profile retrieved successfully"
          },
          "401": {
            "description": "Unauthorized – missing or invalid token"
          },
          "500": {
            "description": "Server error"
          }
        }
      },
      "put": {
        "tags": [
          "User"
        ],
        "summary": "Update logged-in user's profile",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "example": "Usman Talib"
                  },
                  "phone": {
                    "type": "string",
                    "example": "03001234567"
                  },
                  "gender": {
                    "type": "string",
                    "enum": [
                      "male",
                      "female",
                      "other"
                    ],
                    "example": "male"
                  },
                  "dob": {
                    "type": "string",
                    "format": "date",
                    "example": "1995-08-15"
                  },
                  "bio": {
                    "type": "string",
                    "example": "Full-stack developer from Lahore"
                  },
                  "address": {
                    "type": "string",
                    "example": "123 Main Street"
                  },
                  "city": {
                    "type": "string",
                    "example": "Lahore"
                  },
                  "country": {
                    "type": "string",
                    "example": "Pakistan"
                  },
                  "profile_image": {
                    "type": "string",
                    "format": "binary"
                  },
                  "social_links": {
                    "type": "string",
                    "example": "{\"twitter\":\"https://twitter.com/usman\",\"linkedin\":\"https://linkedin.com/in/usman\"}"
                  },
                  "preferences": {
                    "type": "string",
                    "example": "{\"theme\":\"dark\",\"language\":\"en\"}"
                  },
                  "notifications_enabled": {
                    "type": "boolean",
                    "example": true,
                    "description": "Notification preference (true = enabled, false = disabled; stored as 1 or 0 in DB)"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Profile updated successfully",
            "content": {
              "application/json": {
                "example": {
                  "message": "Profile updated successfully"
                }
              }
            }
          },
          "400": {
            "description": "Bad request - missing or invalid fields"
          },
          "401": {
            "description": "Unauthorized - missing or invalid token"
          },
          "500": {
            "description": "Server error"
          }
        }
      }
    },
    "/api/users/profile_photo": {
      "delete": {
        "tags": [
          "User"
        ],
        "summary": "Remove user's profile image",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Profile image removed successfully",
            "content": {
              "application/json": {
                "example": {
                  "message": "Profile image removed and reset to default"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - Missing or invalid token"
          },
          "404": {
            "description": "User not found"
          },
          "500": {
            "description": "Server error"
          }
        }
      }
    },
    "/api/users/settings": {
      "get": {
        "tags": [
          "User"
        ],
        "summary": "Get logged-in user's settings",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "User settings retrieved successfully",
            "content": {
              "application/json": {
                "example": {
                  "preferences": {
                    "theme": "dark",
                    "language": "en"
                  },
                  "notifications_enabled": true,
                  "is_2fa_enabled": false
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - missing or invalid token"
          },
          "500": {
            "description": "Server error"
          }
        }
      },
      "put": {
        "tags": [
          "User"
        ],
        "summary": "Update logged-in user's settings",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "preferences": {
                    "type": "object",
                    "example": {
                      "theme": "dark",
                      "language": "en"
                    }
                  },
                  "notifications_enabled": {
                    "type": "boolean",
                    "example": true
                  },
                  "is_2fa_enabled": {
                    "type": "boolean",
                    "example": false
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Settings updated successfully",
            "content": {
              "application/json": {
                "example": {
                  "message": "Settings updated successfully"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - missing or invalid token"
          },
          "500": {
            "description": "Server error"
          }
        }
      }
    },
    "/api/dashboard/summary": {
      "get": {
        "tags": ["Dashboard"],
        "summary": "Get income, expense & stock summary by period",
        "security": [{"BearerAuth": []}],
        "parameters": [
          {
            "name": "period",
            "in": "query",
            "schema": { "type": "string", "enum": ["daily", "weekly", "monthly"] },
            "example": "monthly",
            "required": false
          }
        ],
        "responses": {
          "200": {
            "description": "Summary fetched successfully",
            "content": {
              "application/json": {
                "example": {
                  "period": "monthly",
                  "total_income": 50000,
                  "total_expense": 20000,
                  "net_balance": 30000,
                  "low_stock_items": 2
                }
              }
            }
          },
          "500": { "description": "Server error" }
        }
      }
    },
    "/api/dashboard/graph": {
      "get": {
        "tags": ["Dashboard"],
        "summary": "Get income vs expense graph data",
        "security": [{"BearerAuth": []}],
        "parameters": [
          { "name": "startDate", "in": "query", "schema": { "type": "string", "format": "date" } },
          { "name": "endDate", "in": "query", "schema": { "type": "string", "format": "date" } }
        ],
        "responses": {
          "200": {
            "description": "Graph data fetched",
            "content": {
              "application/json": {
                "example": [
                  { "date": "2025-10-01", "total_income": 10000, "total_expense": 7000 },
                  { "date": "2025-10-02", "total_income": 15000, "total_expense": 5000 }
                ]
              }
            }
          },
          "500": { "description": "Server error" }
        }
      }
    },
    "/api/dashboard/stock-alerts": {
      "get": {
        "tags": ["Dashboard"],
        "summary": "Get low inventory stock alerts",
        "security": [{"BearerAuth": []}],
        "responses": {
          "200": {
            "description": "Stock alerts retrieved",
            "content": {
              "application/json": {
                "example": {
                  "total_alerts": 2,
                  "alerts": [
                    { "id": 1, "name": "Sugar", "quantity": 2, "min_quantity": 5, "status": "Low Stock" }
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/api/dashboard/reminders": {
      "get": {
        "tags": ["Dashboard"],
        "summary": "Get pending or upcoming reminders",
        "security": [{"BearerAuth": []}],
        "responses": {
          "200": {
            "description": "Reminders fetched successfully",
            "content": {
              "application/json": {
                "example": [
                  { "id": 1, "title": "Pay Electricity Bill", "due_date": "2025-10-30", "status": "pending" }
                ]
              }
            }
          }
        }
      }
    },
    "/api/dashboard/overview": {
      "get": {
        "tags": ["Dashboard"],
        "summary": "Get combined dashboard overview",
        "security": [{"BearerAuth": []}],
        "responses": {
          "200": {
            "description": "Dashboard overview retrieved",
            "content": {
              "application/json": {
                "example": {
                  "total_income": 80000,
                  "total_expense": 55000,
                  "profit_loss": 25000,
                  "low_stock": [
                    { "id": 3, "name": "Milk", "quantity": 2, "min_quantity": 5 }
                  ],
                  "reminders": [
                    { "id": 4, "title": "Client Meeting", "due_date": "2025-10-28" }
                  ]
                }
              }
            }
          }
        }
      }
    },

    "/api/customers/add": {
      "post": {
        "tags": [
          "Customer Management"
        ],
        "summary": "Add a new customer",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "description": "Creates a new customer record with contact details.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "example": "John Doe"
                  },
                  "email": {
                    "type": "string",
                    "example": "john@example.com"
                  },
                  "phone": {
                    "type": "string",
                    "example": "+123456789"
                  },
                  "address": {
                    "type": "string",
                    "example": "123 Main Street"
                  }
                },
                "required": [
                  "name",
                  "phone"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Customer added successfully"
          },
          "500": {
            "description": "Database or server error"
          }
        }
      }
    },
    "/api/customers/edit/{id}": {
      "put": {
        "tags": [
          "Customer Management"
        ],
        "summary": "Edit customer details",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "email": {
                    "type": "string"
                  },
                  "phone": {
                    "type": "string"
                  },
                  "address": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Customer updated successfully"
          },
          "404": {
            "description": "Customer not found"
          },
          "500": {
            "description": "Database or server error"
          }
        }
      }
    },
    "/api/customers/delete/{id}": {
      "delete": {
        "tags": [
          "Customer Management"
        ],
        "summary": "Delete customer",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Customer deleted successfully"
          },
          "404": {
            "description": "Customer not found"
          },
          "500": {
            "description": "Database or server error"
          }
        }
      }
    },
    "/api/customers/all": {
      "get": {
        "tags": [
          "Customer Management"
        ],
        "summary": "Get all customers with full details",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "description": "Fetches all customers including contact info, document links, credit records, and communication logs.",
        "responses": {
          "200": {
            "description": "List of all customers",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "integer"
                      },
                      "name": {
                        "type": "string"
                      },
                      "email": {
                        "type": "string"
                      },
                      "phone": {
                        "type": "string"
                      },
                      "address": {
                        "type": "string"
                      },
                      "documents": {
                        "type": "string"
                      },
                      "credits": {
                        "type": "string"
                      },
                      "communications": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Database or server error"
          }
        }
      }
    },
    "/api/customers/upload-doc": {
      "post": {
        "tags": [
          "Customer Management"
        ],
        "summary": "Upload customer document (Photo ID, Proof, etc.)",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "customerId": {
                    "type": "integer",
                    "example": 5
                  },
                  "docType": {
                    "type": "string",
                    "example": "Photo ID"
                  },
                  "file": {
                    "type": "string",
                    "format": "binary"
                  }
                },
                "required": [
                  "customerId",
                  "file"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Document uploaded successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string",
                      "example": "Document saved"
                    },
                    "docId": {
                      "type": "integer",
                      "example": 12
                    },
                    "filePath": {
                      "type": "string",
                      "example": "uploads/1730128349-285992345.png"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "No file uploaded"
          },
          "500": {
            "description": "Server error"
          }
        }
      }
    },
    "/api/customers/documents/{customerId}": {
      "get": {
        "tags": [
          "Customer Management"
        ],
        "summary": "Get all uploaded documents for a customer",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "customerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            },
            "description": "Customer ID to fetch documents for"
          }
        ],
        "responses": {
          "200": {
            "description": "List of customer documents",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "integer"
                      },
                      "doc_type": {
                        "type": "string",
                        "example": "Proof of Address"
                      },
                      "file_name": {
                        "type": "string",
                        "example": "passport.png"
                      },
                      "file_path": {
                        "type": "string",
                        "example": "uploads/1730128349-285992345.png"
                      },
                      "mime_type": {
                        "type": "string",
                        "example": "image/png"
                      },
                      "uploaded_at": {
                        "type": "string",
                        "format": "date-time"
                      }
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Server error"
          }
        }
      }
    },
    "/api/customers/documents/edit/{id}": {
      "put": {
        "tags": [
          "Customer Management"
        ],
        "summary": "Edit or replace a customer document",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            },
            "description": "Document ID"
          }
        ],
        "requestBody": {
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "docType": {
                    "type": "string",
                    "example": "Updated Proof"
                  },
                  "file": {
                    "type": "string",
                    "format": "binary"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Document updated successfully"
          },
          "404": {
            "description": "Document not found"
          },
          "500": {
            "description": "Server error"
          }
        }
      }
    },
    "/api/customers/documents/delete/{id}": {
      "delete": {
        "tags": [
          "Customer Management"
        ],
        "summary": "Delete a customer document",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            },
            "description": "Document ID"
          }
        ],
        "responses": {
          "200": {
            "description": "Document deleted successfully"
          },
          "404": {
            "description": "Document not found"
          },
          "500": {
            "description": "Server error"
          }
        }
      }
    },
    "/api/customers/credit": {
      "post": {
        "tags": [
          "Customer Management"
        ],
        "summary": "Link customer credit or loan record",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "customerId": {
                    "type": "integer",
                    "example": 4
                  },
                  "amount": {
                    "type": "number",
                    "example": 15000
                  },
                  "type": {
                    "type": "string",
                    "example": "loan"
                  },
                  "interest_rate": {
                    "type": "number",
                    "example": 5.5
                  },
                  "due_date": {
                    "type": "string",
                    "format": "date",
                    "example": "2025-12-30"
                  },
                  "status": {
                    "type": "string",
                    "example": "active"
                  },
                  "note": {
                    "type": "string",
                    "example": "Business loan for stock purchase"
                  }
                },
                "required": [
                  "customerId",
                  "amount",
                  "type"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Credit or loan record created successfully"
          },
          "400": {
            "description": "Invalid input"
          },
          "500": {
            "description": "Server error"
          }
        }
      }
    },
    "/api/customers/credit/{customerId}": {
      "get": {
        "tags": [
          "Customer Management"
        ],
        "summary": "Get all credit/loan records of a customer",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "customerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            },
            "description": "Customer ID"
          }
        ],
        "responses": {
          "200": {
            "description": "List of all customer credit/loan records",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "integer"
                      },
                      "amount": {
                        "type": "number"
                      },
                      "type": {
                        "type": "string",
                        "example": "loan"
                      },
                      "interest_rate": {
                        "type": "number"
                      },
                      "due_date": {
                        "type": "string",
                        "format": "date"
                      },
                      "status": {
                        "type": "string",
                        "example": "active"
                      },
                      "note": {
                        "type": "string"
                      },
                      "created_at": {
                        "type": "string",
                        "format": "date-time"
                      }
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "No records found"
          }
        }
      }
    },
    "/api/customers/credit/edit/{id}": {
      "put": {
        "tags": [
          "Customer Management"
        ],
        "summary": "Edit customer credit or loan record",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "amount": {
                    "type": "number"
                  },
                  "interest_rate": {
                    "type": "number"
                  },
                  "due_date": {
                    "type": "string"
                  },
                  "status": {
                    "type": "string"
                  },
                  "note": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Credit or loan record updated successfully"
          },
          "404": {
            "description": "Record not found"
          }
        }
      }
    },
    "/api/customers/credit/delete/{id}": {
      "delete": {
        "tags": [
          "Customer Management"
        ],
        "summary": "Delete customer credit or loan record",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Credit record deleted successfully"
          },
          "404": {
            "description": "Record not found"
          }
        }
      }
    },
    "/api/customers/communication": {
      "post": {
        "tags": [
          "Customer Management"
        ],
        "summary": "Log customer communication",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "customerId": {
                    "type": "integer",
                    "example": 4
                  },
                  "type": {
                    "type": "string",
                    "example": "SMS"
                  },
                  "message": {
                    "type": "string",
                    "example": "Reminder for pending payment"
                  },
                  "sent_at": {
                    "type": "string",
                    "format": "date-time",
                    "example": "2025-10-25T14:30:00Z"
                  }
                },
                "required": [
                  "customerId",
                  "type",
                  "message"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Communication log saved successfully"
          },
          "500": {
            "description": "Server error"
          }
        }
      }
    },
    "/api/customers/communication/{customerId}": {
      "get": {
        "tags": [
          "Customer Management"
        ],
        "summary": "Get all communications with a customer",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "customerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            },
            "description": "Customer ID"
          }
        ],
        "responses": {
          "200": {
            "description": "List of all communications with customer",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "integer"
                      },
                      "type": {
                        "type": "string"
                      },
                      "message": {
                        "type": "string"
                      },
                      "sent_at": {
                        "type": "string",
                        "format": "date-time"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/customers/communication/edit/{id}": {
      "put": {
        "tags": [
          "Customer Management"
        ],
        "summary": "Edit communication entry",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            },
            "description": "Communication ID to edit"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string",
                    "example": "SMS"
                  },
                  "message": {
                    "type": "string",
                    "example": "Reminder for payment"
                  },
                  "sent_at": {
                    "type": "string",
                    "format": "date-time",
                    "example": "2025-10-25T14:30:00Z"
                  }
                },
                "required": [
                  "type",
                  "message"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Communication updated successfully"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Communication not found"
          },
          "500": {
            "description": "Server error"
          }
        }
      }
    },
    "/api/customers/communication/delete/{id}": {
      "delete": {
        "tags": [
          "Customer Management"
        ],
        "summary": "Delete a communication log entry",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Communication deleted successfully"
          },
          "404": {
            "description": "Communication not found"
          }
        }
      }
    },
    "/api/stock/category/add": {
      "post": {
        "tags": [
          "Stock Management"
        ],
        "summary": "Add new category",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "example": "Electronics"
                  },
                  "type": {
                    "type": "string",
                    "example": "product"
                  }
                },
                "required": [
                  "name"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Category added successfully"
          },
          "500": {
            "description": "Server error"
          }
        }
      }
    },
    "/api/stock/category/edit/{id}": {
      "put": {
        "tags": [
          "Stock Management"
        ],
        "summary": "Edit category details",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "type": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Category updated successfully"
          }
        }
      }
    },
    "/api/stock/category/delete/{id}": {
      "delete": {
        "tags": [
          "Stock Management"
        ],
        "summary": "Delete category",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Category deleted successfully"
          }
        }
      }
    },
    "/api/stock/category/all": {
      "get": {
        "tags": [
          "Stock Management"
        ],
        "summary": "Get all categories",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "List of categories",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "integer"
                      },
                      "name": {
                        "type": "string"
                      },
                      "type": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/stock/subcategory/add": {
      "post": {
        "tags": [
          "Stock Management"
        ],
        "summary": "Add new subcategory",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "category_id": {
                    "type": "integer",
                    "example": 1
                  },
                  "name": {
                    "type": "string",
                    "example": "Mobile Phones"
                  }
                },
                "required": [
                  "category_id",
                  "name"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Subcategory added successfully"
          }
        }
      }
    },
    "/api/stock/subcategory/edit/{id}": {
      "put": {
        "tags": [
          "Stock Management"
        ],
        "summary": "Edit subcategory details",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "category_id": {
                    "type": "integer"
                  },
                  "name": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Subcategory updated successfully"
          }
        }
      }
    },
    "/api/stock/subcategory/delete/{id}": {
      "delete": {
        "tags": [
          "Stock Management"
        ],
        "summary": "Delete subcategory",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Subcategory deleted successfully"
          }
        }
      }
    },
    "/api/stock/subcategory/all": {
      "get": {
        "tags": [
          "Stock Management"
        ],
        "summary": "Get all subcategories",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "List of subcategories",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "integer"
                      },
                      "name": {
                        "type": "string"
                      },
                      "category_id": {
                        "type": "integer"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/stock/item/add": {
      "post": {
        "tags": [
          "Stock Management"
        ],
        "summary": "Add new stock item",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "example": "iPhone 15"
                  },
                  "category_id": {
                    "type": "integer",
                    "example": 1
                  },
                  "subcategory_id": {
                    "type": "integer",
                    "example": 2
                  },
                  "quantity": {
                    "type": "integer",
                    "example": 50
                  },
                  "unit_price": {
                    "type": "number",
                    "example": 250000
                  },
                  "min_quantity": {
                    "type": "integer",
                    "example": 5
                  }
                },
                "required": [
                  "name"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Stock item added successfully"
          }
        }
      }
    },
    "/api/stock/item/edit/{id}": {
      "put": {
        "tags": [
          "Stock Management"
        ],
        "summary": "Edit stock item details",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "category_id": {
                    "type": "integer"
                  },
                  "subcategory_id": {
                    "type": "integer"
                  },
                  "quantity": {
                    "type": "integer"
                  },
                  "unit_price": {
                    "type": "number"
                  },
                  "min_quantity": {
                    "type": "integer"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Stock item updated successfully"
          }
        }
      }
    },
    "/api/stock/item/delete/{id}": {
      "delete": {
        "tags": [
          "Stock Management"
        ],
        "summary": "Delete stock item",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Stock item deleted successfully"
          }
        }
      }
    },
    "/api/stock/item/all": {
      "get": {
        "tags": [
          "Stock Management"
        ],
        "summary": "Get all stock items",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "List of stock items with category/subcategory",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "integer"
                      },
                      "name": {
                        "type": "string"
                      },
                      "quantity": {
                        "type": "integer"
                      },
                      "unit_price": {
                        "type": "number"
                      },
                      "category_name": {
                        "type": "string"
                      },
                      "subcategory_name": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/stock/transaction/add": {
      "post": {
        "tags": [
          "Stock Management"
        ],
        "summary": "Add stock transaction (purchase/sale)",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "stock_id": {
                    "type": "integer",
                    "example": 1
                  },
                  "type": {
                    "type": "string",
                    "example": "purchase"
                  },
                  "quantity": {
                    "type": "integer",
                    "example": 10
                  },
                  "total": {
                    "type": "number",
                    "example": 50000
                  }
                },
                "required": [
                  "stock_id",
                  "type",
                  "quantity"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Transaction added successfully"
          }
        }
      }
    },
    "/api/stock/transaction/edit/{id}": {
      "put": {
        "tags": [
          "Stock Management"
        ],
        "summary": "Edit stock transaction",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "quantity": {
                    "type": "integer"
                  },
                  "total": {
                    "type": "number"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Transaction updated successfully"
          }
        }
      }
    },
    "/api/stock/transaction/delete/{id}": {
      "delete": {
        "tags": [
          "Stock Management"
        ],
        "summary": "Delete stock transaction",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Transaction deleted successfully"
          }
        }
      }
    },
    "/api/stock/alert/all": {
      "get": {
        "tags": [
          "Stock Management"
        ],
        "summary": "Get low stock alerts",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Low stock items",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "integer"
                      },
                      "name": {
                        "type": "string"
                      },
                      "quantity": {
                        "type": "integer"
                      },
                      "min_quantity": {
                        "type": "integer"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/staff/add": {
      "post": {
        "tags": [
          "Staff Management"
        ],
        "summary": "Add new staff member",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "example": "Ali Raza"
                  },
                  "email": {
                    "type": "string",
                    "example": "ali@bizmate.com"
                  },
                  "phone": {
                    "type": "string",
                    "example": "03001234567"
                  },
                  "role": {
                    "type": "string",
                    "example": "manager"
                  },
                  "salary": {
                    "type": "number",
                    "example": 55000
                  }
                },
                "required": [
                  "name",
                  "phone",
                  "role"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Staff added successfully"
          },
          "500": {
            "description": "Server error"
          }
        }
      }
    },
    "/api/staff/edit/{id}": {
      "put": {
        "tags": [
          "Staff Management"
        ],
        "summary": "Edit staff details",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "email": {
                    "type": "string"
                  },
                  "phone": {
                    "type": "string"
                  },
                  "role": {
                    "type": "string"
                  },
                  "salary": {
                    "type": "number"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Staff updated successfully"
          },
          "404": {
            "description": "Staff not found"
          }
        }
      }
    },
    "/api/staff/delete/{id}": {
      "delete": {
        "tags": [
          "Staff Management"
        ],
        "summary": "Delete staff member",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Staff deleted successfully"
          },
          "404": {
            "description": "Staff not found"
          }
        }
      }
    },
    "/api/staff/all": {
      "get": {
        "tags": [
          "Staff Management"
        ],
        "summary": "Get all staff members",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "List of all staff",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "integer"
                      },
                      "name": {
                        "type": "string"
                      },
                      "email": {
                        "type": "string"
                      },
                      "phone": {
                        "type": "string"
                      },
                      "role": {
                        "type": "string"
                      },
                      "salary": {
                        "type": "number"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/staff/assign-role/{id}": {
      "put": {
        "tags": [
          "Staff Management"
        ],
        "summary": "Assign role and permissions to staff",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "role": {
                    "type": "string",
                    "example": "admin"
                  },
                  "permissions": {
                    "type": "object",
                    "example": {
                      "canEdit": true,
                      "canDelete": false
                    }
                  }
                },
                "required": [
                  "role"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Role and permissions updated successfully"
          }
        }
      }
    },
    "/api/staff/payout/add": {
      "post": {
        "tags": [
          "Staff Management"
        ],
        "summary": "Add salary payout record",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "staff_id": {
                    "type": "integer",
                    "example": 3
                  },
                  "amount": {
                    "type": "number",
                    "example": 40000
                  },
                  "date": {
                    "type": "string",
                    "format": "date",
                    "example": "2025-10-01"
                  },
                  "note": {
                    "type": "string",
                    "example": "October payout"
                  }
                },
                "required": [
                  "staff_id",
                  "amount"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Payout added"
          }
        }
      }
    },
    "/api/staff/payout/edit/{id}": {
      "put": {
        "tags": [
          "Staff Management"
        ],
        "summary": "Edit payout record",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "amount": {
                    "type": "number"
                  },
                  "date": {
                    "type": "string"
                  },
                  "note": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Payout updated successfully"
          }
        }
      }
    },
    "/api/staff/payout/delete/{id}": {
      "delete": {
        "tags": [
          "Staff Management"
        ],
        "summary": "Delete payout record",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Payout deleted successfully"
          }
        }
      }
    },
    "/api/staff/attendance/add": {
      "post": {
        "tags": [
          "Staff Management"
        ],
        "summary": "Add attendance record",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "staff_id": {
                    "type": "integer",
                    "example": 3
                  },
                  "date": {
                    "type": "string",
                    "example": "2025-10-20"
                  },
                  "hours_worked": {
                    "type": "number",
                    "example": 8
                  },
                  "status": {
                    "type": "string",
                    "example": "Present"
                  }
                },
                "required": [
                  "staff_id",
                  "date"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Attendance added successfully"
          }
        }
      }
    },
    "/api/staff/attendance/edit/{id}": {
      "put": {
        "tags": [
          "Staff Management"
        ],
        "summary": "Edit attendance record",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "date": {
                    "type": "string"
                  },
                  "hours_worked": {
                    "type": "number"
                  },
                  "status": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Attendance updated successfully"
          }
        }
      }
    },
    "/api/staff/attendance/delete/{id}": {
      "delete": {
        "tags": [
          "Staff Management"
        ],
        "summary": "Delete attendance record",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Attendance deleted successfully"
          }
        }
      }
    },
    "/api/staff/performance/add": {
      "post": {
        "tags": [
          "Staff Management"
        ],
        "summary": "Add performance note",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "staff_id": {
                    "type": "integer",
                    "example": 3
                  },
                  "note": {
                    "type": "string",
                    "example": "Excellent leadership this month"
                  }
                },
                "required": [
                  "staff_id",
                  "note"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Performance note added"
          }
        }
      }
    },
    "/api/staff/performance/edit/{id}": {
      "put": {
        "tags": [
          "Staff Management"
        ],
        "summary": "Edit performance note",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "note": {
                    "type": "string",
                    "example": "Improved time management"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Performance note updated successfully"
          }
        }
      }
    },
    "/api/staff/performance/delete/{id}": {
      "delete": {
        "tags": [
          "Staff Management"
        ],
        "summary": "Delete performance note",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Performance note deleted successfully"
          }
        }
      }
    },
    "/api/finance/source/add": {
      "post": {
        "tags": [
          "Finance Management"
        ],
        "summary": "Add a new income source",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "example": "Product Sales"
                  },
                  "description": {
                    "type": "string",
                    "example": "Sales from products"
                  }
                },
                "required": [
                  "name"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Income source added successfully"
          },
          "500": {
            "description": "Server error"
          }
        }
      }
    },
    "/api/finance/source/edit/{id}": {
      "put": {
        "tags": [
          "Finance Management"
        ],
        "summary": "Edit income source",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "example": "Updated Sales"
                  },
                  "description": {
                    "type": "string",
                    "example": "Edited description"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Income source updated successfully"
          },
          "404": {
            "description": "Income source not found"
          }
        }
      }
    },
    "/api/finance/source/delete/{id}": {
      "delete": {
        "tags": [
          "Finance Management"
        ],
        "summary": "Delete income source",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Income source deleted successfully"
          },
          "404": {
            "description": "Not found"
          }
        }
      }
    },
    "/api/finance/source/all": {
      "get": {
        "tags": [
          "Finance Management"
        ],
        "summary": "Get all income sources",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "List of income sources",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "integer"
                      },
                      "name": {
                        "type": "string"
                      },
                      "description": {
                        "type": "string"
                      },
                      "created_at": {
                        "type": "string",
                        "format": "date-time"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/finance/record/add": {
      "post": {
        "tags": [
          "Finance Management"
        ],
        "summary": "Add income record",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "source_id": {
                    "type": "integer",
                    "example": 1
                  },
                  "amount": {
                    "type": "number",
                    "example": 1500.50
                  },
                  "date": {
                    "type": "string",
                    "example": "2025-10-25"
                  },
                  "note": {
                    "type": "string",
                    "example": "Client project payment"
                  }
                },
                "required": [
                  "source_id",
                  "amount"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Income record added"
          }
        }
      }
    },
    "/api/finance/record/edit/{id}": {
      "put": {
        "tags": [
          "Finance Management"
        ],
        "summary": "Edit income record",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "source_id": {
                    "type": "integer",
                    "example": 2
                  },
                  "amount": {
                    "type": "number",
                    "example": 1750
                  },
                  "date": {
                    "type": "string",
                    "example": "2025-10-26"
                  },
                  "note": {
                    "type": "string",
                    "example": "Adjusted amount"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Income record updated"
          },
          "404": {
            "description": "Income record not found"
          }
        }
      }
    },
    "/api/finance/record/delete/{id}": {
      "delete": {
        "tags": [
          "Finance Management"
        ],
        "summary": "Delete income record",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Income record deleted successfully"
          },
          "404": {
            "description": "Income record not found"
          }
        }
      }
    },
    "/api/finance/record/all": {
      "get": {
        "tags": [
          "Finance Management"
        ],
        "summary": "Get all income records",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "List of income records with source name",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "integer"
                      },
                      "source_name": {
                        "type": "string"
                      },
                      "amount": {
                        "type": "number"
                      },
                      "date": {
                        "type": "string"
                      },
                      "note": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/finance/reminder/add": {
      "post": {
        "tags": [
          "Finance Management"
        ],
        "summary": "Add income reminder",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "income_id": {
                    "type": "integer",
                    "example": 3
                  },
                  "reminder_date": {
                    "type": "string",
                    "example": "2025-11-01"
                  },
                  "message": {
                    "type": "string",
                    "example": "Follow up on payment"
                  }
                },
                "required": [
                  "income_id",
                  "reminder_date"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Reminder added successfully"
          }
        }
      }
    },
    "/api/finance/reminder/all": {
      "get": {
        "tags": [
          "Finance Management"
        ],
        "summary": "Get all upcoming reminders",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "List of upcoming income reminders",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "integer"
                      },
                      "income_id": {
                        "type": "integer"
                      },
                      "reminder_date": {
                        "type": "string"
                      },
                      "message": {
                        "type": "string"
                      },
                      "source_name": {
                        "type": "string"
                      },
                      "amount": {
                        "type": "number"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/finance/sale/add": {
      "post": {
        "tags": [
          "Finance Management"
        ],
        "summary": "Create a sale / income record",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "invoice_no": {
                    "type": "string"
                  },
                  "customer_id": {
                    "type": "integer"
                  },
                  "staff_id": {
                    "type": "integer"
                  },
                  "source_id": {
                    "type": "integer"
                  },
                  "total_amount": {
                    "type": "number"
                  },
                  "paid_amount": {
                    "type": "number"
                  },
                  "date": {
                    "type": "string",
                    "format": "date"
                  },
                  "notes": {
                    "type": "string"
                  }
                },
                "required": [
                  "total_amount",
                  "date"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Sale recorded"
          }
        }
      }
    },
    "/api/finance/sale/edit/{id}": {
      "put": {
        "tags": [
          "Finance Management"
        ],
        "summary": "Edit sale",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Sale updated"
          }
        }
      }
    },
    "/api/finance/sale/delete/{id}": {
      "delete": {
        "tags": [
          "Finance Management"
        ],
        "summary": "Delete sale",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Sale deleted"
          }
        }
      }
    },
    "/api/finance/sale/all": {
      "get": {
        "tags": [
          "Finance Management"
        ],
        "summary": "Get sales (filters: staff_id, customer_id, from, to, min_amount, max_amount)",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "staff_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "customer_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "List of sales"
          }
        }
      }
    },
    "/api/finance/category/add": {
      "post": {
        "tags": [
          "Finance Management"
        ],
        "summary": "Add expense category",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "is_personal": {
                    "type": "boolean"
                  }
                },
                "required": [
                  "name"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Expense category added"
          }
        }
      }
    },
    "/api/finance/category/all": {
      "get": {
        "tags": [
          "Finance Management"
        ],
        "summary": "Get expense categories",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "List of expense categories"
          }
        }
      }
    },
    "/api/finance/expense/add": {
      "post": {
        "tags": [
          "Finance Management"
        ],
        "summary": "Add expense",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "category_id": {
                    "type": "integer"
                  },
                  "amount": {
                    "type": "number"
                  },
                  "date": {
                    "type": "string",
                    "format": "date"
                  },
                  "description": {
                    "type": "string"
                  },
                  "is_business": {
                    "type": "boolean"
                  }
                },
                "required": [
                  "amount",
                  "date"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Expense added"
          }
        }
      }
    },
    "/api/finance/expense/edit/{id}": {
      "put": {
        "tags": [
          "Finance Management"
        ],
        "summary": "Edit expense",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Expense updated"
          }
        }
      }
    },
    "/api/finance/expense/delete/{id}": {
      "delete": {
        "tags": [
          "Finance Management"
        ],
        "summary": "Delete expense",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Expense deleted"
          }
        }
      }
    },
    "/api/finance/expense/all": {
      "get": {
        "tags": [
          "Finance Management"
        ],
        "summary": "Get expenses (filters: from, to, category_id, is_business)",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "List of expenses"
          }
        }
      }
    },
    "/api/finance/loan/add": {
      "post": {
        "tags": [
          "Finance Management"
        ],
        "summary": "Create loan record (lend/borrow)",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "party_name": {
                    "type": "string"
                  },
                  "type": {
                    "type": "string",
                    "example": "lend"
                  },
                  "principal": {
                    "type": "number"
                  },
                  "interest_rate": {
                    "type": "number"
                  },
                  "start_date": {
                    "type": "string",
                    "format": "date"
                  },
                  "due_date": {
                    "type": "string",
                    "format": "date"
                  },
                  "notes": {
                    "type": "string"
                  }
                },
                "required": [
                  "party_name",
                  "type",
                  "principal",
                  "start_date"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Loan record created"
          }
        }
      }
    },
    "/api/finance/loan/edit/{id}": {
      "put": {
        "tags": [
          "Finance Management"
        ],
        "summary": "Edit loan",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Loan updated"
          }
        }
      }
    },
    "/api/finance/loan/delete/{id}": {
      "delete": {
        "tags": [
          "Finance Management"
        ],
        "summary": "Delete loan",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Loan deleted"
          }
        }
      }
    },
    "/api/finance/loan/all": {
      "get": {
        "tags": [
          "Finance Management"
        ],
        "summary": "Get loans (filters: status, party)",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "List of loans"
          }
        }
      }
    },
    "/api/finance/loan/repayment/add": {
      "post": {
        "tags": [
          "Finance Management"
        ],
        "summary": "Add loan repayment",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "loan_id": {
                    "type": "integer"
                  },
                  "amount": {
                    "type": "number"
                  },
                  "date": {
                    "type": "string",
                    "format": "date"
                  },
                  "note": {
                    "type": "string"
                  }
                },
                "required": [
                  "loan_id",
                  "amount",
                  "date"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Repayment recorded"
          }
        }
      }
    },
    "/api/finance/loan/repayment/all": {
      "get": {
        "tags": [
          "Finance Management"
        ],
        "summary": "Get repayments for a loan (query: ?loan_id=)",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "loan_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "List of repayments"
          }
        }
      }
    },
    "/api/finance/investment/add": {
      "post": {
        "tags": [
          "Finance Management"
        ],
        "summary": "Add investment",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "title": {
                    "type": "string"
                  },
                  "amount": {
                    "type": "number"
                  },
                  "invested_on": {
                    "type": "string",
                    "format": "date"
                  },
                  "matured_on": {
                    "type": "string",
                    "format": "date"
                  },
                  "profit_amount": {
                    "type": "number"
                  },
                  "notes": {
                    "type": "string"
                  }
                },
                "required": [
                  "title",
                  "amount",
                  "invested_on"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Investment added"
          }
        }
      }
    },
    "/api/finance/investment/edit/{id}": {
      "put": {
        "tags": [
          "Finance Management"
        ],
        "summary": "Edit investment",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Investment updated"
          }
        }
      }
    },
    "/api/finance/investment/delete/{id}": {
      "delete": {
        "tags": [
          "Finance Management"
        ],
        "summary": "Delete investment",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Investment deleted"
          }
        }
      }
    },
    "/api/finance/investment/all": {
      "get": {
        "tags": [
          "Finance Management"
        ],
        "summary": "Get investments",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "List of investments"
          }
        }
      }
    },
    "/api/finance/investment/roi/{id}": {
      "get": {
        "tags": [
          "Finance Management"
        ],
        "summary": "Get ROI for an investment",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "ROI percent and basic data"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT"
      }
    }
  }
}