{
    "openapi": "3.0.0",
    "info": {
        "title": "Leads API",
        "description": "A simple API for managing leads",
        "version": "1.0.0"
    },
    "paths": {
        "/api/v1/leads": {
            "get": {
                "summary": "List all own leads",
                "operationId": "listOwnLeads",
                "parameters": [
                    {
                        "name": "x-api-key",
                        "in": "header",
                        "description": "Authorization key from site",
                        "required": true,
                        "schema": {
                            "type": "string",
                            "example": "77e1c83b-7bb0-437b-bc50-a7a58e5660ac"
                        }
                    },
                    {
                        "name": "page",
                        "in": "query",
                        "description": "The page number to return",
                        "required": false,
                        "schema": {
                            "type": "integer",
                            "minimum": 1,
                            "default": 1
                        }
                    },
                    {
                        "name": "per_page",
                        "in": "query",
                        "description": "The number of items per page",
                        "required": false,
                        "schema": {
                            "type": "integer",
                            "minimum": 1,
                            "default": 15
                        }
                    },
                    {
                        "name": "from_date",
                        "in": "query",
                        "description": "Since date YYYY-MM-DD",
                        "required": false,
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "to_date",
                        "in": "query",
                        "description": "Before date YYYY-MM-DD",
                        "required": false,
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "A list of own leads",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "allOf": [
                                        {
                                            "$ref": "#/components/schemas/PaginationResponse"
                                        },
                                        {
                                            "type": "object",
                                            "properties": {
                                                "data": {
                                                    "type": "array",
                                                    "items": {
                                                        "$ref": "#/components/schemas/Lead"
                                                    }
                                                }
                                            },
                                            "required": ["data"]
                                        }
                                    ]
                                }
                            }
                        }
                    }
                }
            },
            "post": {
                "summary": "Create a new lead",
                "operationId": "createLead",
                "parameters": [
                    {
                        "name": "x-api-key",
                        "in": "header",
                        "description": "Authorization key from site",
                        "required": true,
                        "schema": {
                            "type": "string",
                            "example": "77e1c83b-7bb0-437b-bc50-a7a58e5660ac"
                        }
                    }
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "firstName": {
                                        "type": "string",
                                        "example": "Jessica"
                                    },
                                    "lastName": {
                                        "type": "string",
                                        "example": "Smith"
                                    },
                                    "country": {
                                        "type": "string",
                                        "example": "Uk"
                                    },
                                    "offer": {
                                        "type": "string",
                                        "example": "offer-test"
                                    },
                                    "lang": {
                                        "type": "string",
                                        "example": "en"
                                    },
                                    "phone": {
                                        "type": "string",
                                        "example": "448569857412"
                                    },
                                    "email": {
                                        "type": "string",
                                        "example": "email@gmail.com"
                                    },
                                    "description": {
                                        "type": "string",
                                        "example": "Информация о предыдущем взаимодействии с лидом, комментарии например"
                                    }
                                },
                                "required": ["firstName", "email", "phone", "country"]
                            }
                        }
                    }
                },
                "responses": {
                    "201": {
                        "description": "Lead created successfully",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "code": {
                                            "type": "int",
                                            "example": 201
                                        },
                                        "message": {
                                            "type": "string",
                                            "example": "OK"
                                        },
                                        "data": {
                                            "type": "object",
                                            "properties": {
                                                "id": { "type": "integer", "example": 12413 }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "Lead": {
                "type": "object",
                "required": ["id", "status"],
                "properties": {
                    "id": {
                        "type": "integer",
                        "example": 22142,
                        "description": "Unique identifier for the lead on site"
                    },
                    "status": {
                        "type": "string",
                        "example": "New",
                        "description": "Lead current status"
                    }
                }
            },
            "ApiResponse": {
                "type": "object",
                "required": ["message", "code"],
                "properties": {
                    "id": {
                        "type": "integer",
                        "example": 22142,
                        "description": "Unique identifier for the lead on site"
                    },
                    "status": {
                        "type": "string",
                        "example": "New",
                        "description": "Lead current status"
                    }
                }
            },
            "PaginationResponse": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "array",
                        "description": "The array of resource items for the current page"
                    },
                    "links": {
                        "type": "object",
                        "properties": {
                            "first": { "type": "string", "nullable": true, "format": "uri" , "example": "https://example.com/v1/api/resource?page=1"},
                            "last": { "type": "string", "nullable": true, "format": "uri" , "example": "https://example.com/v1/api/resource?page=10"},
                            "prev": { "type": "string", "nullable": true, "format": "uri", "example": "https://example.com/v1/api/resource?page=1" },
                            "next": { "type": "string", "nullable": true, "format": "uri", "example": "https://example.com/v1/api/resource?page=2" }
                        }
                    },
                    "meta": {
                        "type": "object",
                        "properties": {
                            "current_page": { "type": "integer", "example": 2 },
                            "from": { "type": "integer", "nullable": true, "example": 1 },
                            "last_page": { "type": "integer", "example": 10 },
                            "links": {
                                "type": "array",
                                "items": {
                                    "type": "object",
                                    "properties": {
                                        "url": { "type": "string", "nullable": true, "format": "uri" },
                                        "label": { "type": "string" },
                                        "active": { "type": "boolean" }
                                    }
                                }
                            },
                            "path": { "type": "string", "format": "uri" },
                            "per_page": { "type": "integer", "example": 15 },
                            "to": { "type": "integer", "nullable": true },
                            "total": { "type": "integer", "example": 145 }
                        }
                    }
                },
                "required": ["data", "links", "meta"]
            }
        }
    }
}
