"""Map Core connection status onto the Cloud execute-time three-state.

Core keeps its own catalog statuses (active, disconnected, error, pending,
reauthentication_required).
Cloud only needs to know whether a mirrored connection is executable
(active), not yet usable (configuration_required), or connected-but-unhealthy
(degraded). This mapper is the only place that translation happens so Cloud
does not re-interpret Core policy.
"""
from __future__ import annotations

from src.domain.connectors.models import ConnectorConnectionStatus

_ACTIVE = frozenset({"active", "ready", "installed"})
_DEGRADED = frozenset({"degraded", "error"})


def cloud_connector_runtime_status(status: str | ConnectorConnectionStatus | None) -> str:
    """Return ``active``, ``configuration_required``, or ``degraded``."""
    raw = status.value if isinstance(status, ConnectorConnectionStatus) else (status or "")
    normalized = str(raw).strip().lower()
    if normalized in _ACTIVE:
        return "active"
    if normalized in _DEGRADED:
        return "degraded"
    return "configuration_required"
