# import requests
# import json

# # Функция авторизации
# def authorize(username, password):
#     url = "https://online.bnovo.ru/"
#     headers = {
#         "accept": "application/json",
#         "Content-Type": "application/json"
#     }
#     payload = {
#         "username": username,
#         "password": password
#     }
    
#     response = requests.post(url, headers=headers, json=payload, allow_redirects=False)
#     print(f"[DEBUG] Статус авторизации: {response.status_code}")
#     print(f"[DEBUG] Заголовки ответа: {response.headers}")
    
#     if response.status_code == 302 and "SID" in response.cookies:
#         sid = response.cookies.get("SID")
#         print(f"[DEBUG] Получен SID: {sid}")
#         return sid
#     else:
#         raise ValueError(f"Ошибка авторизации: {response.text}")

# # Функция получения данных с /dashboard
# def fetch_dashboard(sid, create_from, create_to, status_ids, page=1, count=10):
#     url = f"https://online.bnovo.ru/dashboard"
#     headers = {
#         "accept": "application/json",
#         "Cookie": f"SID={sid}"
#     }
#     params = {
#         "create_from": create_from,
#         "create_to": create_to,
#         "advanced_search": 2,
#         "status_ids": status_ids,
#         "c": count,
#         "page": page,
#         "order_by": "create_date.asc"
#     }
    
#     response = requests.get(url, headers=headers, params=params)
#     print(f"[DEBUG] Статус запроса: {response.status_code}")
#     print(f"[DEBUG] Ответ: {json.dumps(response.json(), indent=2, ensure_ascii=False)}")
    
#     if response.status_code == 200:
#         return response.json()
#     else:
#         raise ValueError(f"Ошибка при запросе данных: {response.text}")

# # Тестовый вызов
# try:
#     username = "cto@hotelantifraud.ru"
#     password = "tD8wC1zP9tiT6mY1"
    
#     # Авторизация
#     sid = authorize(username, password)
    
#     # Получение бронирований
#     bookings = fetch_dashboard(
#         sid=sid,
#         create_from="25.09.2024",
#         create_to="05.10.2024",
#         status_ids="1",
#         page=1,
#         count=10
#     )
#     print(f"[INFO] Полученные бронирования: {json.dumps(bookings, indent=2, ensure_ascii=False)}")

# except Exception as e:
#     print(f"[ERROR] {e}")
