"""
Проверка, что все сервисы запущены
"""

import requests
from requests.auth import HTTPBasicAuth

SERVICES = [
    {
        "name": "Spectrometer",
        "url": "http://localhost:1818/api/",
        "auth": None,
    },
    {
        "name": "Reconstructor",
        "url": "http://localhost:8081/health",
        "auth": ("admin", "admin"),
    },
    {
        "name": "Orchestrator",
        "url": "http://localhost:1717/scenario/list",
        "auth": None,
    },
]


def check_service(name, url, auth=None):
    try:
        r = requests.get(
            url,
            timeout=5,
            auth=HTTPBasicAuth(*auth) if auth else None,
        )
        r.raise_for_status()
        print(f"[OK] {name} OK ({r.status_code})")
        return True
    except Exception as e:
        print(f"[FAIL] {name} FAIL: {e}")
        return False


if __name__ == "__main__":
    all_ok = True
    for service in SERVICES:
        if not check_service(service["name"], service["url"], service["auth"]):
            all_ok = False

    if all_ok:
        print("\nAll services are up [OK]")
    else:
        print("\nSome services failed [FAIL]")
