{
 "openapi": "3.1.0",
 "info": {
  "title": "Ember Spa Lounge API",
  "version": "1.0",
  "description": "Открытый JSON API салона (массаж, спа, баня и сауна, Алматы): компания, услуги, прайс «от», предварительный расчёт. Без ключа, только чтение. Цены «от» по прайсу сайта. Точную стоимость и время подтверждает администратор в WhatsApp. Подготовка записи (POST /booking) — с токеном OAuth 2.1, scope booking:prepare: https://emberspa.kz/auth.md. Ответ — текст записи и ссылка WhatsApp для человека; сайт ничего не отправляет.",
  "contact": {
   "url": "https://emberspa.kz/"
  }
 },
 "servers": [
  {
   "url": "https://emberspa.kz/api/v1"
  }
 ],
 "paths": {
  "/company.json": {
   "get": {
    "summary": "Салон и контакты",
    "operationId": "company_json",
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Company"
        }
       }
      }
     }
    }
   }
  },
  "/services.json": {
   "get": {
    "summary": "Услуги с ценой «от»",
    "operationId": "services_json",
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Services"
        }
       }
      }
     }
    }
   }
  },
  "/prices.json": {
   "get": {
    "summary": "Прайс /ceny/",
    "operationId": "prices_json",
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Prices"
        }
       }
      }
     }
    }
   }
  },
  "/reviews.json": {
   "get": {
    "summary": "Отзывы гостей из 2ГИС: оценка, число оценок и отзывов, до десяти отзывов",
    "operationId": "reviews_json",
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Reviews"
        }
       }
      }
     }
    }
   }
  },
  "/health": {
   "get": {
    "summary": "Состояние API",
    "operationId": "health",
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Health"
        }
       }
      }
     }
    }
   }
  },
  "/estimate": {
   "get": {
    "summary": "Предварительный расчёт по прайсу",
    "operationId": "estimate_get",
    "parameters": [
     {
      "name": "items",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string"
      },
      "example": "sauna-pochasovo:3,klassicheskij:1"
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Estimate"
        },
        "example": {
         "items": [
          {
           "id": "sauna-pochasovo",
           "name": "Сауна с бассейном почасово",
           "qty": 3,
           "price_from": 5000,
           "sum_from": 15000
          },
          {
           "id": "klassicheskij",
           "name": "Классический массаж",
           "qty": 1,
           "price_from": 15000,
           "sum_from": 15000
          }
         ],
         "total_from": 30000,
         "min_order_applied": false,
         "total_text": "от 30 000 ₸"
        }
       }
      }
     },
     "400": {
      "description": "Неверные позиции"
     }
    }
   },
   "post": {
    "summary": "Предварительный расчёт по прайсу (JSON)",
    "operationId": "estimate_post",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "items"
        ],
        "properties": {
         "items": {
          "type": "array",
          "items": {
           "type": "object",
           "required": [
            "id",
            "qty"
           ],
           "properties": {
            "id": {
             "type": "string"
            },
            "qty": {
             "type": "integer",
             "minimum": 1,
             "description": "сеансы, курсы или часы сауны (минимум 3 часа)"
            }
           }
          }
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Estimate"
        }
       }
      }
     }
    }
   }
  },
  "/booking": {
   "post": {
    "summary": "Подготовка записи: текст и ссылка WhatsApp (ничего не отправляет)",
    "operationId": "booking_prepare",
    "description": "Только с токеном OAuth 2.1 (Bearer, scope booking:prepare); как получить — https://emberspa.kz/auth.md. Собирает текст записи (услуга, вариант, время, число гостей, имя, комментарий) и возвращает ссылку WhatsApp с ним и телефон салона. Сайт ничего не отправляет и не сохраняет — сообщение администратору отправляет сам человек.",
    "security": [
     {
      "oauth2": [
       "booking:prepare"
      ]
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/BookingRequest"
       },
       "example": {
        "service": "klassicheskij",
        "option": "60 мин",
        "when": "завтра после 19:00",
        "lang": "ru"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Запись подготовлена (не отправлена)",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Booking"
        }
       }
      }
     },
     "400": {
      "description": "Неверные поля (bad_request, service_required, unknown_service, unknown_option)",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Нет токена или он негоден",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      },
      "headers": {
       "WWW-Authenticate": {
        "description": "Bearer resource_metadata=\"https://emberspa.kz/.well-known/oauth-protected-resource/api/v1/booking\", scope=\"booking:prepare\" (+ error при негодном токене)",
        "schema": {
         "type": "string"
        }
       }
      }
     },
     "403": {
      "description": "Нет права booking:prepare или подготовка записи выключена",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "415": {
      "description": "Тело — не application/json",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "Лимит запросов",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      },
      "headers": {
       "Retry-After": {
        "schema": {
         "type": "integer"
        }
       }
      }
     }
    }
   }
  }
 },
 "components": {
  "schemas": {
   "Company": {
    "type": "object",
    "required": [
     "name",
     "phone"
    ],
    "properties": {
     "name": {
      "type": "string"
     },
     "phone": {
      "type": "object"
     }
    }
   },
   "Services": {
    "type": "object",
    "required": [
     "services"
    ],
    "properties": {
     "services": {
      "type": "array"
     }
    }
   },
   "Prices": {
    "type": "object",
    "required": [
     "sections"
    ],
    "properties": {
     "sections": {
      "type": "array"
     }
    }
   },
   "Reviews": {
    "type": "object",
    "required": [
     "rating",
     "reviews_count",
     "fetched_at",
     "reviews"
    ],
    "properties": {
     "rating": {
      "type": "number"
     },
     "reviews_count": {
      "type": "integer"
     },
     "fetched_at": {
      "type": "string"
     },
     "reviews": {
      "type": "array"
     }
    }
   },
   "Health": {
    "type": "object",
    "properties": {
     "ok": {
      "type": "boolean"
     }
    }
   },
   "Estimate": {
    "type": "object",
    "required": [
     "items",
     "total_from",
     "total_text",
     "disclaimer"
    ],
    "properties": {
     "items": {
      "type": "array"
     },
     "total_from": {
      "type": [
       "integer",
       "null"
      ]
     },
     "total_text": {
      "type": "string"
     },
     "disclaimer": {
      "type": "string"
     }
    }
   },
   "BookingRequest": {
    "type": "object",
    "required": [
     "service"
    ],
    "additionalProperties": false,
    "properties": {
     "service": {
      "type": "string",
      "description": "id услуги из /services.json"
     },
     "option": {
      "type": "string",
      "maxLength": 60,
      "description": "вариант из price_examples, например «60 мин»"
     },
     "when": {
      "type": "string",
      "maxLength": 80
     },
     "guests": {
      "type": "integer",
      "minimum": 1,
      "maximum": 20
     },
     "name": {
      "type": "string",
      "maxLength": 60
     },
     "comment": {
      "type": "string",
      "maxLength": 300
     },
     "pool": {
      "type": "boolean",
      "description": "true — пожелание: сауна с бассейном (бассейн входит в аренду сауны; в ответе pool_note с ценой из прайса)"
     },
     "lang": {
      "type": "string",
      "enum": [
       "ru",
       "en"
      ]
     }
    }
   },
   "Booking": {
    "type": "object",
    "required": [
     "ok",
     "prepared",
     "sent",
     "message_text",
     "whatsapp_url"
    ],
    "properties": {
     "ok": {
      "type": "boolean"
     },
     "prepared": {
      "type": "boolean"
     },
     "sent": {
      "type": "boolean",
      "const": false
     },
     "message_text": {
      "type": "string"
     },
     "whatsapp_url": {
      "type": "string",
      "format": "uri"
     },
     "phone": {
      "type": "object"
     },
     "service": {
      "type": "object"
     },
     "hours": {
      "type": [
       "string",
       "null"
      ]
     },
     "next_step": {
      "type": "string"
     },
     "pool_note": {
      "type": "string"
     }
    }
   },
   "Error": {
    "type": "object",
    "required": [
     "error"
    ],
    "properties": {
     "error": {
      "type": "object",
      "required": [
       "code",
       "message"
      ],
      "properties": {
       "code": {
        "type": "string"
       },
       "message": {
        "type": "string"
       }
      }
     }
    }
   }
  },
  "securitySchemes": {
   "oauth2": {
    "type": "oauth2",
    "description": "OAuth 2.1 сайта: регистрация клиента — https://emberspa.kz/oauth/register (RFC 7591), метаданные — https://emberspa.kz/.well-known/oauth-authorization-server (RFC 8414), https://emberspa.kz/.well-known/oauth-protected-resource и https://emberspa.kz/.well-known/oauth-protected-resource/api/v1/booking (RFC 9728); как войти — https://emberspa.kz/auth.md.",
    "flows": {
     "clientCredentials": {
      "tokenUrl": "https://emberspa.kz/oauth/token",
      "scopes": {
       "booking:prepare": "Подготовка записи для человека"
      }
     },
     "authorizationCode": {
      "authorizationUrl": "https://emberspa.kz/oauth/authorize",
      "tokenUrl": "https://emberspa.kz/oauth/token",
      "refreshUrl": "https://emberspa.kz/oauth/token",
      "scopes": {
       "booking:prepare": "Подготовка записи для человека"
      }
     }
    }
   }
  }
 }
}
