"""Smoke test: app imports, /api/health returns 200, version string present."""

from __future__ import annotations

import pytest
from fastapi.testclient import TestClient


def test_health_endpoint(tmp_data_dir) -> None:  # noqa: ARG001 — fixture applies env
    from notify_bridge_server.main import app

    # TestClient runs the lifespan on enter/exit, so migrations run once
    # against the temp data dir — a genuine integration smoke check.
    with TestClient(app) as client:
        resp = client.get("/api/health")
        assert resp.status_code == 200
        body = resp.json()
        assert body["status"] == "ok"
        assert body["version"] != "0.0.0+unknown"
        assert "." in body["version"]  # looks like a real version


def test_ready_endpoint(tmp_data_dir) -> None:  # noqa: ARG001
    from notify_bridge_server.main import app

    with TestClient(app) as client:
        resp = client.get("/api/ready")
        # By the time TestClient yields, lifespan startup has completed.
        assert resp.status_code == 200
        body = resp.json()
        assert body["ready"] is True
        assert body["checks"]["db"] == "ok"
        assert body["checks"]["scheduler"] == "ok"
        # No HA providers configured by default in the test fixture.
        assert body["checks"]["ha"] == "na"
        assert body["errors"] == []


def test_health_is_anonymous(tmp_data_dir) -> None:  # noqa: ARG001
    """/api/health must not require auth — the Docker healthcheck depends on it."""
    from notify_bridge_server.main import app

    with TestClient(app) as client:
        resp = client.get("/api/health")
        assert resp.status_code == 200
