# Lawneu Booking API Update

Live base URL:

```text
https://page.law.indias.cloud/api/v1
```

## Booking Submit

Endpoint:

```text
POST /book.php
```

Headers:

```text
Content-Type: application/json
X-API-KEY: admin_secret_key
```

New behavior:

- Saves booking in `bookings`.
- Saves the first client message in `booking_messages`.
- Sends notification email to advocate `contact_email` or `global_settings.admin_email`.
- Logs delivery in `email_logs`.
- Returns a thank-you popup message.

Success response:

```json
{
  "success": true,
  "message": "Thank you. Your booking request has been received. We will reply soon.",
  "popup": "Thank you. Your booking request has been received. We will reply soon.",
  "booking_id": 15
}
```

## Messages API

Endpoint:

```text
/messages.php
```

Admin auth:

```text
X-API-KEY: admin_secret_key
```

Master auth:

```text
Authorization: Bearer YOUR_MASTER_KEY
```

or:

```text
X-Master-Key: YOUR_MASTER_KEY
```

### List

```bash
curl "https://page.law.indias.cloud/api/v1/messages.php?action=list&advocate_id=1" \
  -H "X-API-KEY: admin_secret_key"
```

Master can list all without `advocate_id`:

```bash
curl "https://page.law.indias.cloud/api/v1/messages.php?action=list" \
  -H "Authorization: Bearer YOUR_MASTER_KEY"
```

### Read

```bash
curl "https://page.law.indias.cloud/api/v1/messages.php?action=read&booking_id=15&advocate_id=1" \
  -H "X-API-KEY: admin_secret_key"
```

### Reply

```bash
curl -X POST "https://page.law.indias.cloud/api/v1/messages.php?action=reply&advocate_id=1" \
  -H "X-API-KEY: admin_secret_key" \
  -H "Content-Type: application/json" \
  -d '{"booking_id":15,"message":"Thank you. We will call you soon."}'
```

Reply response:

```json
{
  "success": true,
  "message": "Reply saved and emailed.",
  "email_sent": true,
  "email_error": ""
}
```

If email fails, the reply remains saved and the failure is logged in `email_logs`.

## Browser Access

```text
/manage/messages.php?advocate_id=1
/zlawpanel/
```

The existing `/manage` booking cards now include a `Read / Reply` button.
Master admin access should use `/zlawpanel/`.

## Email Settings

Recommended environment variables:

```text
SMTP_HOST
SMTP_PORT
SMTP_USER
SMTP_PASSWORD
SMTP_FROM
SMTP_SECURE
```

Equivalent `global_settings` keys:

```text
smtp_host
smtp_port
smtp_user
smtp_password
mail_from
smtp_secure
admin_email
```

If SMTP is not configured, the app falls back to PHP `mail()`.

## Database

New tables:

```text
booking_messages
email_logs
```
