# Updated Client Creation API

## POST /api/admin/clients

Create a new client with company onboarding details.

### Required Fields
- `name` - Contact person name (string, max 255)
- `company_name` - Company name (string, max 255)
- `email` - Company email (valid email, max 255)
- `mobile` - Primary mobile number (string, max 20)

### Optional Fields
- `alternate_mobile` - Secondary mobile (string, max 20)
- `gst_number` - GST registration number (string, max 50)
- `address` - Company address (text)

### Auto-Generated
- `api_key` - Unique API key (face_xxx format)
- `price_plan` - Set to 'free_trial' by default
- `is_active` - Set to true by default

## Example Requests

### Minimal Request
```bash
curl -X POST http://127.0.0.1:8888/api/admin/clients \
  -H "Content-Type: application/json" \
  -d '{
    "name": "John Doe",
    "company_name": "Acme Corp",
    "email": "john@acme.com",
    "mobile": "+919876543210"
  }'
```

**Response (201):**
```json
{
  "message": "Client created successfully",
  "data": {
    "id": 9,
    "name": "John Doe",
    "company_name": "Acme Corp",
    "email": "john@acme.com",
    "mobile": "+919876543210",
    "price_plan": "free_trial",
    "api_key": "face_3fnQ2h1CuIE94PTU5y5IcTivqwjfOK3nb1yJdzoD",
    "is_active": true,
    "created_at": "2026-02-07T11:52:37.000000Z",
    "updated_at": "2026-02-07T11:52:37.000000Z"
  }
}
```

### Full Request (With Optional Fields)
```bash
curl -X POST http://127.0.0.1:8888/api/admin/clients \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Jane Smith",
    "company_name": "Tech Solutions",
    "email": "jane@tech.com",
    "mobile": "+919876543211",
    "alternate_mobile": "+919876543212",
    "gst_number": "29ABCDE1234F1Z5",
    "address": "123 Business Park, Mumbai"
  }'
```

**Response (201):**
```json
{
  "message": "Client created successfully",
  "data": {
    "id": 10,
    "name": "Jane Smith",
    "company_name": "Tech Solutions",
    "email": "jane@tech.com",
    "mobile": "+919876543211",
    "alternate_mobile": "+919876543212",
    "gst_number": "29ABCDE1234F1Z5",
    "address": "123 Business Park, Mumbai",
    "price_plan": "free_trial",
    "api_key": "face_30bQZ07S8Qk8Yl8v8yyw98AFe4vYe9FAmmbwSlfq",
    "is_active": true,
    "created_at": "2026-02-07T11:52:37.000000Z",
    "updated_at": "2026-02-07T11:52:37.000000Z"
  }
}
```

## Validation Errors

### Missing Required Fields
```bash
curl -X POST http://127.0.0.1:8888/api/admin/clients \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Test User",
    "company_name": "Test Company"
  }'
```

**Response (422):**
```json
{
  "message": "The email field is required. (and 1 more error)",
  "errors": {
    "email": ["The email field is required."],
    "mobile": ["The mobile field is required."]
  }
}
```

### Invalid Email
```bash
curl -X POST http://127.0.0.1:8888/api/admin/clients \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Test User",
    "company_name": "Test Company",
    "email": "invalid-email",
    "mobile": "+919876543210"
  }'
```

**Response (422):**
```json
{
  "message": "The email field must be a valid email address.",
  "errors": {
    "email": ["The email field must be a valid email address."]
  }
}
```

## Important Notes

✅ **API Key Visibility**
- API key is **only shown in the create response**
- It will be **hidden** in list/update responses
- Save it immediately after creation

✅ **Price Plan**
- Automatically set to `free_trial`
- Cannot be changed during creation
- Can be updated later via admin panel

✅ **Authentication**
- This endpoint does **NOT require authentication**
- It's for admin use to onboard new clients
- The generated API key is used by clients for face API endpoints

## Postman Example

**Method:** POST  
**URL:** `http://127.0.0.1:8888/api/admin/clients`  
**Headers:**
```
Content-Type: application/json
```
**Body (raw JSON):**
```json
{
  "name": "John Doe",
  "company_name": "Acme Corporation",
  "email": "contact@acme.com",
  "mobile": "+919876543210",
  "alternate_mobile": "+919876543211",
  "gst_number": "29ABCDE1234F1Z5",
  "address": "123 Business Park, Mumbai, India"
}
```

## Changes Summary

### What Changed
- ✅ `company_name` - Now **required**
- ✅ `email` - Now **required**
- ✅ `mobile` - Now **required**
- ✅ `price_plan` - Auto-set to 'free_trial'

### What Stayed Same
- ✅ Route: `POST /api/admin/clients`
- ✅ No authentication required
- ✅ API key generation logic
- ✅ Response format
