# API Documentation

## Authentication API

### Login
- **Endpoint**: `/api/auth/login`
- **Method**: POST
- **Description**: Authenticate user and return access token
- **Request Body**:
  ```json
  {
    "email": "string",
    "password": "string"
  }
  ```
- **Response**:
  ```json
  {
    "access_token": "string",
    "token_type": "bearer",
    "expires_in": 3600,
    "user": {
      "id": "integer",
      "name": "string",
      "email": "string",
      "roles": ["string"]
    }
  }
  ```

### Logout
- **Endpoint**: `/api/auth/logout`
- **Method**: POST
- **Description**: Invalidate user session
- **Headers**: Authorization: Bearer {token}
- **Response**: 204 No Content

## User Management API

### Create User
- **Endpoint**: `/api/users`
- **Method**: POST
- **Description**: Create new user account
- **Headers**: Authorization: Bearer {token}
- **Request Body**:
  ```json
  {
    "name": "string",
    "email": "string",
    "password": "string",
    "roles": ["string"]
  }
  ```
- **Response**: 201 Created

### Get Users
- **Endpoint**: `/api/users`
- **Method**: GET
- **Description**: List all users
- **Headers**: Authorization: Bearer {token}
- **Response**:
  ```json
  {
    "data": [
      {
        "id": "integer",
        "name": "string",
        "email": "string",
        "roles": ["string"],
        "created_at": "datetime"
      }
    ],
    "meta": {
      "current_page": "integer",
      "total": "integer",
      "per_page": "integer"
    }
  }
  ```

## Dealer Management API

### Create Dealer
- **Endpoint**: `/api/dealers`
- **Method**: POST
- **Description**: Create new dealer
- **Headers**: Authorization: Bearer {token}
- **Request Body**:
  ```json
  {
    "name": "string",
    "contact_person": "string",
    "email": "string",
    "phone": "string",
    "address": "string",
    "credit_limit": "decimal"
  }
  ```
- **Response**: 201 Created

### Get Dealers
- **Endpoint**: `/api/dealers`
- **Method**: GET
- **Description**: List all dealers
- **Headers**: Authorization: Bearer {token}
- **Response**:
  ```json
  {
    "data": [
      {
        "id": "integer",
        "name": "string",
        "contact_person": "string",
        "email": "string",
        "phone": "string",
        "address": "string",
        "credit_limit": "decimal",
        "outstanding_balance": "decimal"
      }
    ],
    "meta": {
      "current_page": "integer",
      "total": "integer",
      "per_page": "integer"
    }
  }
  ```

## Inventory Management API

### Create Product
- **Endpoint**: `/api/products`
- **Method**: POST
- **Description**: Create new product
- **Headers**: Authorization: Bearer {token}
- **Request Body**:
  ```json
  {
    "name": "string",
    "sku": "string",
    "description": "string",
    "unit_price": "decimal",
    "reorder_level": "integer"
  }
  ```
- **Response**: 201 Created

### Get Products
- **Endpoint**: `/api/products`
- **Method**: GET
- **Description**: List all products
- **Headers**: Authorization: Bearer {token}
- **Response**:
  ```json
  {
    "data": [
      {
        "id": "integer",
        "name": "string",
        "sku": "string",
        "description": "string",
        "unit_price": "decimal",
        "reorder_level": "integer",
        "current_stock": "integer"
      }
    ],
    "meta": {
      "current_page": "integer",
      "total": "integer",
      "per_page": "integer"
    }
  }
  ```

## Order Management API

### Create Order
- **Endpoint**: `/api/orders`
- **Method**: POST
- **Description**: Create new order
- **Headers**: Authorization: Bearer {token}
- **Request Body**:
  ```json
  {
    "dealer_id": "integer",
    "items": [
      {
        "product_id": "integer",
        "quantity": "integer",
        "unit_price": "decimal"
      }
    ],
    "delivery_date": "date"
  }
  ```
- **Response**: 201 Created

### Get Orders
- **Endpoint**: `/api/orders`
- **Method**: GET
- **Description**: List all orders
- **Headers**: Authorization: Bearer {token}
- **Response**:
  ```json
  {
    "data": [
      {
        "id": "integer",
        "order_number": "string",
        "dealer": {
          "id": "integer",
          "name": "string"
        },
        "total_amount": "decimal",
        "status": "string",
        "created_at": "datetime"
      }
    ],
    "meta": {
      "current_page": "integer",
      "total": "integer",
      "per_page": "integer"
    }
  }
  ```

## Financial Management API

### Create Voucher
- **Endpoint**: `/api/vouchers`
- **Method**: POST
- **Description**: Create new voucher
- **Headers**: Authorization: Bearer {token}
- **Request Body**:
  ```json
  {
    "type": "string",
    "date": "date",
    "description": "string",
    "amount": "decimal",
    "account_head_id": "integer"
  }
  ```
- **Response**: 201 Created

### Get Financial Reports
- **Endpoint**: `/api/reports/financial`
- **Method**: GET
- **Description**: Get financial reports
- **Headers**: Authorization: Bearer {token}
- **Query Parameters**:
  - start_date: date
  - end_date: date
  - report_type: string
- **Response**:
  ```json
  {
    "data": {
      "summary": {
        "total_income": "decimal",
        "total_expense": "decimal",
        "net_profit": "decimal"
      },
      "details": [
        {
          "date": "date",
          "description": "string",
          "amount": "decimal",
          "type": "string"
        }
      ]
    }
  }
  ```

## Error Responses
All API endpoints may return the following error responses:

### 400 Bad Request
```json
{
  "message": "Validation failed",
  "errors": {
    "field": ["error message"]
  }
}
```

### 401 Unauthorized
```json
{
  "message": "Unauthenticated"
}
```

### 403 Forbidden
```json
{
  "message": "This action is unauthorized"
}
```

### 404 Not Found
```json
{
  "message": "Resource not found"
}
```

### 500 Server Error
```json
{
  "message": "Server Error"
}
``` 
