# Update Profile

Update user profile information. Supports both self-edit and admin modes.

**Endpoints**:
- Self-edit: `PUT /api/auth/profile`
- Admin edit: `PUT /api/auth/profile/:id`

**Auth**: Required
**Content-Type**: `application/json`

## Self-Edit Mode

Users can update their own profile. All fields are optional.

### Request Body

| Field | Type | Required | Description |
|--------|------|-----------|-------------|
| username | string | No | New username (must be unique, 3-50 chars) |
| email | string | No | New email (must be unique, valid format) |
| first_name | string | No | User's first name |
| last_name | string | No | User's last name |
| theme | string | No | Theme preference |

### Example Request

```json
{
  "username": "newusername",
  "email": "newemail@example.com",
  "first_name": "John",
  "last_name": "Smith",
  "theme": "dracula"
}
```

## Admin Mode

Admins can update any user by providing the user ID in the URL. Additionally supports role changes.

**URL Parameter**: `:id` - Target user's UUID

### Additional Request Body Fields (Admin Only)

| Field | Type | Required | Description |
|--------|------|-----------|-------------|
| role | string | No | New role: "user" or "admin" |

### Example Admin Request

```json
{
  "username": "newusername",
  "email": "newemail@example.com",
  "role": "admin"
}
```

## Response (200 OK)

```json
{
  "id": "uuid",
  "email": "user@example.com",
  "username": "john",
  "first_name": "John",
  "last_name": "Smith",
  "theme": "dracula",
  "role": "user",
  "max_devices": 10,
  "created_at": "2026-01-31T10:00:00Z"
}
```

## Error Responses

| Code | Description |
|------|-------------|
| 400 | Invalid input data or invalid role |
| 401 | Invalid or expired token |
| 403 | Admin access required (admin mode only) |
| 404 | User not found (admin mode only) |
| 409 | Username or email already taken |
