# Help Desk Assignment API Documentation

## Update Help Desk Assignment

### Endpoint

`PATCH /help-desk/assign/:id`

### Description

Updates the `assigned_to` field of a help desk ticket. This allows assigning or unassigning support agents to help desk tickets.

### Authentication

Requires JWT authentication token in the Authorization header.

### Request Parameters

#### Path Parameters

- `id` (string, required): The help desk ticket ID

#### Request Body

```json
{
  "assigned_to": "60f7b2b5e4b0c8a2b8c9d0e1" // User ID or null to unassign
}
```

### Request Body Schema

- `assigned_to` (string, optional): The user ID to assign the ticket to. Can be null or empty string to unassign the ticket.

### Response

#### Success Response (200 OK)

```json
{
  "status": 200,
  "data": {
    "_id": "60f7b2b5e4b0c8a2b8c9d0e2",
    "name": "John Doe",
    "email": "john.doe@example.com",
    "phone": "+1234567890",
    "query": "Need help with property registration",
    "status": "pending",
    "service_type": "legal_opinion",
    "type_of_call": "app",
    "user_id": {
      "_id": "60f7b2b5e4b0c8a2b8c9d0e3",
      "name": "Customer Name",
      "email": "customer@example.com"
    },
    "assigned_to": {
      "_id": "60f7b2b5e4b0c8a2b8c9d0e1",
      "name": "Support Agent",
      "email": "agent@example.com"
    },
    "createdAt": "2024-01-15T10:30:00.000Z",
    "updatedAt": "2024-01-15T11:45:00.000Z"
  },
  "message": "Help desk assigned successfully",
  "success": true
}
```

#### Error Responses

##### 400 Bad Request

```json
{
  "error": "Invalid help desk ID",
  "success": false
}
```

##### 404 Not Found

```json
{
  "error": "Help desk ticket not found",
  "success": false
}
```

##### 500 Internal Server Error

```json
{
  "error": "Failed to update help desk assignment",
  "success": false,
  "details": "Error message details"
}
```

### Example Usage

#### Assign a user to help desk

```bash
curl -X PATCH http://localhost:3000/help-desk/assign/60f7b2b5e4b0c8a2b8c9d0e2 \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "assigned_to": "60f7b2b5e4b0c8a2b8c9d0e1"
  }'
```

#### Unassign a user from help desk

```bash
curl -X PATCH http://localhost:3000/help-desk/assign/60f7b2b5e4b0c8a2b8c9d0e2 \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "assigned_to": null
  }'
```

### Notes

- The `assigned_to` field can be set to `null` or an empty string to unassign the ticket
- The assigned user must exist in the system
- The response includes populated user information for both the ticket creator and the assigned agent
- The endpoint validates the help desk ID and assigned user ID format
- Only authenticated users can access this endpoint
