# Beach Reservation API Documentation

## Overview
This API allows customers to create and manage beach reservations. All endpoints require authentication using Laravel Sanctum.

## Base URL
```
http://127.0.0.1:8000/api
```

## Authentication
All API requests require a Bearer token. Include the token in the Authorization header:
```
Authorization: Bearer {your-token}
```

## Endpoints

### 1. Get User's Reservations
**GET** `/beach-reservations`

Returns all reservations for the authenticated user.

**Response:**
```json
{
    "success": true,
    "data": [
        {
            "id": 1,
            "user_id": 1,
            "reservation_date": "2025-01-20",
            "full_name": "John Doe",
            "number_of_persons": 4,
            "instagram_link": "https://instagram.com/johndoe",
            "id_head_image": "beach_reservations/id_head_1234567890_abc123.jpg",
            "id_tail_image": "beach_reservations/id_tail_1234567890_def456.jpg",
            "status": "pending",
            "notes": null,
            "created_at": "2025-01-15T10:30:00.000000Z",
            "updated_at": "2025-01-15T10:30:00.000000Z"
        }
    ],
    "message": "Reservations retrieved successfully"
}
```

### 2. Create New Reservation
**POST** `/beach-reservations`

Creates a new beach reservation.

**Request Body (multipart/form-data):**
- `reservation_date` (required): Date in YYYY-MM-DD format (must be after today)
- `full_name` (required): Full name of the person making the reservation
- `number_of_persons` (required): Number of persons (1-50)
- `instagram_link` (required): Valid Instagram profile URL
- `id_head_image` (required): Image file (JPEG, PNG, JPG, max 2MB)
- `id_tail_image` (required): Image file (JPEG, PNG, JPG, max 2MB)

**Response:**
```json
{
    "success": true,
    "data": {
        "id": 1,
        "user_id": 1,
        "reservation_date": "2025-01-20",
        "full_name": "John Doe",
        "number_of_persons": 4,
        "instagram_link": "https://instagram.com/johndoe",
        "id_head_image": "beach_reservations/id_head_1234567890_abc123.jpg",
        "id_tail_image": "beach_reservations/id_tail_1234567890_def456.jpg",
        "status": "pending",
        "notes": null,
        "created_at": "2025-01-15T10:30:00.000000Z",
        "updated_at": "2025-01-15T10:30:00.000000Z"
    },
    "message": "Beach reservation created successfully"
}
```

### 3. Get Specific Reservation
**GET** `/beach-reservations/{id}`

Returns details of a specific reservation (only if owned by the authenticated user).

**Response:**
```json
{
    "success": true,
    "data": {
        "id": 1,
        "user_id": 1,
        "reservation_date": "2025-01-20",
        "full_name": "John Doe",
        "number_of_persons": 4,
        "instagram_link": "https://instagram.com/johndoe",
        "id_head_image": "beach_reservations/id_head_1234567890_abc123.jpg",
        "id_tail_image": "beach_reservations/id_tail_1234567890_def456.jpg",
        "status": "pending",
        "notes": null,
        "created_at": "2025-01-15T10:30:00.000000Z",
        "updated_at": "2025-01-15T10:30:00.000000Z"
    },
    "message": "Reservation retrieved successfully"
}
```

### 4. Update Reservation
**PUT** `/beach-reservations/{id}`

Updates a reservation (only if status is pending).

**Request Body:**
```json
{
    "reservation_date": "2025-01-25",
    "full_name": "John Doe Updated",
    "number_of_persons": 6,
    "instagram_link": "https://instagram.com/johndoe_updated"
}
```

**Response:**
```json
{
    "success": true,
    "data": {
        "id": 1,
        "user_id": 1,
        "reservation_date": "2025-01-25",
        "full_name": "John Doe Updated",
        "number_of_persons": 6,
        "instagram_link": "https://instagram.com/johndoe_updated",
        "id_head_image": "beach_reservations/id_head_1234567890_abc123.jpg",
        "id_tail_image": "beach_reservations/id_tail_1234567890_def456.jpg",
        "status": "pending",
        "notes": null,
        "created_at": "2025-01-15T10:30:00.000000Z",
        "updated_at": "2025-01-15T10:35:00.000000Z"
    },
    "message": "Reservation updated successfully"
}
```

### 5. Delete Reservation
**DELETE** `/beach-reservations/{id}`

Deletes a reservation (only if status is pending).

**Response:**
```json
{
    "success": true,
    "message": "Reservation deleted successfully"
}
```

### 6. Get Reservation Statistics
**GET** `/beach-reservations/statistics`

Returns statistics for the authenticated user's reservations.

**Response:**
```json
{
    "success": true,
    "data": {
        "total": 5,
        "pending": 2,
        "approved": 2,
        "rejected": 1
    },
    "message": "Statistics retrieved successfully"
}
```

## Error Responses

### Validation Error (422)
```json
{
    "message": "The given data was invalid.",
    "errors": {
        "reservation_date": [
            "The reservation date must be a date after today."
        ],
        "number_of_persons": [
            "The number of persons must be at least 1."
        ]
    }
}
```

### Unauthorized (401)
```json
{
    "message": "Unauthenticated."
}
```

### Forbidden (403)
```json
{
    "success": false,
    "message": "Unauthorized access"
}
```

### Not Found (404)
```json
{
    "message": "No query results for model [App\\Models\\BeachReservation] 1"
}
```

## Status Codes
- `pending`: Reservation is waiting for approval
- `approved`: Reservation has been approved
- `rejected`: Reservation has been rejected

## File Upload Requirements
- **ID Head Image**: JPEG, PNG, or JPG format, maximum 2MB
- **ID Tail Image**: JPEG, PNG, or JPG format, maximum 2MB
- Images are stored in the `storage/app/public/beach_reservations/` directory

## Example Usage with cURL

### Create a Reservation
```bash
curl -X POST http://127.0.0.1:8000/api/beach-reservations \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Accept: application/json" \
  -F "reservation_date=2025-01-20" \
  -F "full_name=John Doe" \
  -F "number_of_persons=4" \
  -F "instagram_link=https://instagram.com/johndoe" \
  -F "id_head_image=@/path/to/id_head.jpg" \
  -F "id_tail_image=@/path/to/id_tail.jpg"
```

### Get User's Reservations
```bash
curl -X GET http://127.0.0.1:8000/api/beach-reservations \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Accept: application/json"
``` 