## Conversation API Documentation

This API allows users to create and manage conversations tied to advertisements. It offers functionalities such as
sending and receiving messages, retrieving conversation details, and listing user conversations. All endpoints are
secured using authentication tokens.

### List of Contents

- [Create Conversation](#1-create-conversation)
- [Send Message](#2-send-message)
- [Conversation Data](#3-conversation-data)
- [List Messages](#4-list-messages)
- [List Conversations](#5-list-conversations)

### Authentication

- Authentication is handled using [Sanctum](https://laravel.com/docs/sanctum) tokens. Ensure that you include a valid
  token in the `Authorization` header of your requests to access protected endpoints.

### Content Type

- All API endpoints operate with `application/json` for both requests and responses.

---

### 1. Create Conversation

- **Endpoint**: `POST /api/v1/conversation/create`
- **Description**: Creates a new conversation for a specified advertisement.
- **Authentication**: Yes
- **Permissions**: User

#### Request Parameters:

| Parameter      | Required/Optional | Type    | Description                        |
|----------------|-------------------|---------|------------------------------------|
| `advertise_id` | Required          | Integer | ID of the advertisement.           |
| `name`         | Required          | String  | Name or title of the conversation. |

#### Request Example:

```json
{
    "advertise_id": 1,
    "name": "Discussion about new offer"
}
```

#### Response Example:

```json
{
    "status": true,
    "message": "success!",
    "data": {
        "conversation_id": 1
    }
}
```

---

### 2. Send Message

- **Endpoint**: `POST /api/v1/conversation/sendMessage`
- **Description**: Sends a message in a specific conversation.
- **Authentication**: Yes
- **Permissions**: User

#### Request Parameters:

| Parameter         | Required/Optional | Type    | Description                         |
|-------------------|-------------------|---------|-------------------------------------|
| `conversation_id` | Required          | Integer | ID of the conversation.             |
| `type`            | Required          | String  | Type of the message (e.g., 'text'). |
| `content`         | Required          | String  | Content of the message.             |

#### Request Example:

```json
{
    "conversation_id": 1,
    "type": "text",
    "content": "Hello, I'm interested in your offer."
}
```

#### Response Example:

```json
{
    "status": true,
    "message": "success!",
    "data": {
        "message_id": 10
    }
}
```

---

### 3. Conversation Data

- **Endpoint**: `POST /api/v1/conversation/data`
- **Description**: Retrieves data for a specific conversation.
- **Authentication**: Yes
- **Permissions**: User

#### Request Parameters:

| Parameter         | Required/Optional | Type    | Description             |
|-------------------|-------------------|---------|-------------------------|
| `conversation_id` | Required          | Integer | ID of the conversation. |

#### Request Example:

```json
{
    "conversation_id": 15
}
```

#### Response Example:

```json
{
    "status": true,
    "message": "success!",
    "data": {
        "conversation": {
            "id": 15,
            "name": "Discussion about new offer",
            "advertise": {
                "title": "New product for sale",
                "slug": "new-product-for-sale",
                "meta_data": {
                    "id": 1,
                    "data": {}
                }
            },
            "creator": {
                "id": 1,
                "name": "John Doe",
                "username": "johndoe"
            },
            "created_at": "2024-09-14T10:00:00.000000Z"
        }
    }
}
```

---

### 4. List Messages

- **Endpoint**: `POST /api/v1/conversation/messages`
- **Description**: Retrieves all messages for a specific conversation.
- **Authentication**: Yes
- **Permissions**: User

#### Request Parameters:

| Parameter         | Required/Optional | Type    | Description             |
|-------------------|-------------------|---------|-------------------------|
| `conversation_id` | Required          | Integer | ID of the conversation. |

#### Request Example:

```json
{
    "conversation_id": 1
}
```

#### Response Example:

```json
{
    "status": true,
    "message": "success!",
    "data": {
        "conversation_id": 1,
        "messages": [
            {
                "id": 101,
                "sender": {
                    "id": 1,
                    "name": "John Doe",
                    "user_name": "john_doe",
                    "email": "johndoe@example.com"
                },
                "type": "text",
                "content": "Hello, I'm interested in your offer.",
                "data": null,
                "sent_at": "2024-09-14T10:15:00.000000Z"
            },
            {
                "id": 75,
                "sender": {
                    "id": 2,
                    "name": "David Harrison",
                    "user_name": "david_harrison",
                    "email": "david@example.com"
                },
                "type": "text",
                "content": "Hello, Nice! Let's Negotiate.",
                "data": null,
                "sent_at": "2024-09-14T10:15:00.000000Z"
            }
        ]
    }
}
```

---

### 5. List Conversations

- **Endpoint**: `POST /api/v1/conversation/list`
- **Description**: Retrieves a list of conversations for the authenticated user.
- **Authentication**: Yes
- **Permissions**: User

#### Request Example:

No parameters required.

#### Response Example:

```json
{
    "status": true,
    "message": "success!",
    "data": {
        "user_id": 1,
        "conversations": [
            {
                "id": 15,
                "name": "Discussion about new offer",
                "advertise": {
                    "title": "New product for sale",
                    "image_link": "https://example.com/product.jpg"
                },
                "created_at": "2024-09-14T10:00:00.000000Z"
            },
            {
                "id": 7,
                "name": "Check if product exist",
                "advertise": {
                    "title": "New Mobile For Sale",
                    "image_link": "https://example.com/mobile.jpg"
                },
                "created_at": "2024-09-14T10:00:00.000000Z"
            }
        ]
    }
}
```

---
