from __future__ import annotations

import os
import sys
from pathlib import Path

from dotenv import load_dotenv

BASE_DIR = Path(__file__).resolve().parent
load_dotenv(BASE_DIR / ".env.local")
load_dotenv(BASE_DIR / ".env")


def main() -> int:
    try:
        from hockey_data.database import HockeyDatabase

        database = HockeyDatabase(BASE_DIR)
        status = database.schema_status()
        target = (
            f"{status.get('host', '')}:{status.get('port', '')}/"
            f"{status.get('database', '')}"
        )
        print(f"[Hockey DB] PostgreSQL connection OK: {target}")
        database.engine.dispose()
        return 0
    except Exception as error:
        print("\n[Hockey DB] ОШИБКА ПОДКЛЮЧЕНИЯ")
        print(str(error))
        print("\nЗаполните HOCKEY_DATABASE_URL в .env по примеру .env.example.")
        return 1


if __name__ == "__main__":
    raise SystemExit(main())
