{
  "openapi": "3.1.0",
  "info": {"title": "Бутик-отель Ассоль — API для ИИ-ассистентов", "version": "1.0.0",
           "description": "Живая доступность и цены из системы бронирования отеля, бронь по прямой цене с предоплатой картой по ссылке, перенос/отмена, вопрос администратору. Даты YYYY-MM-DD, время московское, деньги в рублях. Ошибки: JSON {error, hint, ...}. Документация: https://agents.assoll.ru/llms.txt",
           "contact": {"email": "hotel@assoll.ru"}},
  "servers": [{"url": "https://agents.assoll.ru/api"}],
  "components": {
    "securitySchemes": {"AgentKey": {"type": "apiKey", "in": "header", "name": "X-Agent-Key", "description": "POST /register → agent_key. Ключи test_* — песочница."}},
    "schemas": {
      "Error": {"type": "object", "properties": {"error": {"type": "string"}, "hint": {"type": "string"}, "alternatives": {"type": "array"}, "retry_after": {"type": "integer"}}, "required": ["error", "hint"]},
      "Offer": {"type": "object", "properties": {"category_id": {"type": "string"}, "name": {"type": "string"}, "available": {"type": "integer"}, "places": {"type": "integer"}, "extra_places": {"type": "integer"}, "view": {"type": "string"}, "area_m2": {"type": "number"}, "rate": {"type": "string"}, "nights": {"type": "integer"},
        "site_price_per_night": {"type": "number"}, "site_total": {"type": "number"}, "direct_price_per_night": {"type": "number", "description": "прямая цена для брони через ассистента"}, "direct_total": {"type": "number"}, "prepayment": {"type": "number", "description": "первая ночь"}, "free_cancellation_until": {"type": "string", "format": "date"}}},
      "Booking": {"type": "object", "properties": {"id": {"type": "string", "example": "AS-261220-7F3A"}, "status": {"type": "string", "enum": ["new", "prepaid", "confirmed", "changed", "cancelled"]}, "category": {"type": "string"}, "date_in": {"type": "string"}, "date_out": {"type": "string"}, "nights": {"type": "integer"}, "adults": {"type": "integer"}, "children": {"type": "array", "items": {"type": "integer"}}, "guest": {"type": "string"}, "phone": {"type": "string"}, "direct_per_night": {"type": "number"}, "total": {"type": "number"}, "prepay": {"type": "number"}, "pay_url": {"type": ["string", "null"]}, "pay_status": {"type": "string"}, "free_cancellation_until": {"type": "string"}, "status_text": {"type": "string"}, "payment_note": {"type": "string"}}},
      "BookingRequest": {"type": "object", "required": ["category_id", "date_in", "date_out", "name", "phone"], "properties": {"category_id": {"type": "string"}, "date_in": {"type": "string", "format": "date"}, "date_out": {"type": "string", "format": "date"}, "adults": {"type": "integer", "default": 2}, "children": {"type": "array", "items": {"type": "integer"}, "description": "возрасты детей"}, "name": {"type": "string"}, "phone": {"type": "string", "example": "+79181234567"}, "email": {"type": "string"}, "comment": {"type": "string"}}}
    }
  },
  "paths": {
    "/health": {"get": {"summary": "Состояние шлюза", "responses": {"200": {"description": "ok"}}}},
    "/rooms": {"get": {"summary": "Категории номеров с category_id, площадью, кроватями, удобствами, фото", "responses": {"200": {"description": "categories[]"}}}},
    "/availability": {"get": {"summary": "Живая доступность и цены на даты", "parameters": [
        {"name": "date_in", "in": "query", "required": true, "schema": {"type": "string", "format": "date"}}, {"name": "date_out", "in": "query", "required": true, "schema": {"type": "string", "format": "date"}},
        {"name": "adults", "in": "query", "schema": {"type": "integer", "default": 2}}, {"name": "children", "in": "query", "schema": {"type": "string"}, "description": "возрасты через запятую: 3,9"}],
      "responses": {"200": {"description": "offers[] (пусто + sales_status=not_open, если продажи на даты не открыты)", "content": {"application/json": {"schema": {"type": "object", "properties": {"offers": {"type": "array", "items": {"$ref": "#/components/schemas/Offer"}}, "fetched_at": {"type": "string"}, "sales_status": {"type": "string"}}}}}}, "400": {"description": "bad_dates / date_in_past", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}}, "503": {"description": "pms_unavailable"}}}},
    "/bookings": {
      "post": {"summary": "Создать бронь по прямой цене", "security": [{"AgentKey": []}], "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/BookingRequest"}}}},
        "responses": {"200": {"description": "{booking, say_to_guest, duplicate?}", "content": {"application/json": {"schema": {"type": "object", "properties": {"booking": {"$ref": "#/components/schemas/Booking"}, "say_to_guest": {"type": "string"}}}}}}, "409": {"description": "no_availability (с alternatives) / too_many_active", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}}, "401": {"description": "agent_key_required"}}},
      "get": {"summary": "Бронь по id или активные брони по телефону", "security": [{"AgentKey": []}], "parameters": [{"name": "booking_id", "in": "query", "schema": {"type": "string"}}, {"name": "phone", "in": "query", "schema": {"type": "string"}}], "responses": {"200": {"description": "bookings[]"}}}},
    "/bookings/{id}": {"get": {"summary": "Бронь по id", "security": [{"AgentKey": []}], "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}], "responses": {"200": {"description": "booking"}, "404": {"description": "booking_not_found"}}}},
    "/bookings/{id}/reschedule": {"post": {"summary": "Перенос дат/категории", "security": [{"AgentKey": []}], "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}], "requestBody": {"content": {"application/json": {"schema": {"type": "object", "properties": {"date_in": {"type": "string"}, "date_out": {"type": "string"}, "category_id": {"type": "string"}, "phone": {"type": "string"}}}}}}, "responses": {"200": {"description": "{booking, say_to_guest}"}, "409": {"description": "no_availability"}}}},
    "/bookings/{id}/cancel": {"post": {"summary": "Отмена", "security": [{"AgentKey": []}], "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}], "requestBody": {"content": {"application/json": {"schema": {"type": "object", "properties": {"reason": {"type": "string"}, "phone": {"type": "string"}}}}}}, "responses": {"200": {"description": "{booking, free_cancellation, say_to_guest}"}}}},
    "/ask": {"post": {"summary": "Вопрос администратору (ответ гостю на телефон)", "security": [{"AgentKey": []}], "requestBody": {"required": true, "content": {"application/json": {"schema": {"type": "object", "required": ["text", "phone"], "properties": {"text": {"type": "string"}, "phone": {"type": "string"}, "name": {"type": "string"}, "booking_id": {"type": "string"}, "force": {"type": "boolean"}}}}}}, "responses": {"200": {"description": "{thread_id, status, eta, say_to_guest} или {auto_answer}"}}}},
    "/threads/{id}": {"get": {"summary": "Статус/ответ по вопросу", "security": [{"AgentKey": []}], "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}], "responses": {"200": {"description": "thread"}}}},
    "/register": {"post": {"summary": "Получить ключ агента", "requestBody": {"required": true, "content": {"application/json": {"schema": {"type": "object", "required": ["agent_name", "contact"], "properties": {"agent_name": {"type": "string"}, "contact": {"type": "string"}}}}}}, "responses": {"200": {"description": "{agent_key, limits}"}}}}
  }
}
