import requests
import json

def test_calendar_via_gateway():
    # Используемый токен
    token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIyOSIsImVtYWlsIjoidGVzdDJAZXhhbXBsZS5jb20iLCJleHAiOjE3NTg4NjQwMzV9.Ap4ZD5EtwhLXRtm6KjuFvXMlk6XA-3HtMbaGEu9jX6M"

    # Базовый URL для API Gateway
    base_url = "http://localhost:8000"
    
    # Заголовки с авторизацией
    headers = {
        "Authorization": f"Bearer {token}",
        "Content-Type": "application/json"
    }
    
    print("Тестирование через API Gateway:")
    print("Используемый токен:", token)
    print("Заголовки:", headers)
    
    try:
        # Проверка /api/v1/calendar/entries через API Gateway
        print("\nОтправка GET запроса на /api/v1/calendar/entries...")
        response = requests.get(f"{base_url}/api/v1/calendar/entries", headers=headers)
        print("GET /api/v1/calendar/entries через Gateway:", response.status_code)
        if response.status_code == 200:
            print("Response:", json.dumps(response.json(), indent=2)[:100] + "...")
        else:
            print("Error response:", response.text)
    except Exception as e:
        print("Ошибка при выполнении GET запроса:", str(e))
    
    try:
        # Проверка /api/v1/entry через API Gateway
        entry_data = {
            "date": "2023-11-15", 
            "type": "period",
            "note": "Test entry",
            "symptoms": ["cramps", "headache"],
            "flow_intensity": "medium"
        }
        
        print("\nОтправка POST запроса на /api/v1/entry...")
        print("Данные:", json.dumps(entry_data, indent=2))
        response = requests.post(f"{base_url}/api/v1/entry", headers=headers, json=entry_data)
        print("POST /api/v1/entry через Gateway:", response.status_code)
        if response.status_code == 201 or response.status_code == 200:
            print("Response:", json.dumps(response.json(), indent=2))
        else:
            print("Error response:", response.text)
    except Exception as e:
        print("Ошибка при выполнении POST запроса:", str(e))

if __name__ == "__main__":
    test_calendar_via_gateway()
