"""Fly.io deployment detection."""

from ..models import Context
from .state import DetectionState


def get_fly_hint(mode: str = "reference") -> str | None:
    """Get activation hint for fly detector."""
    if mode == "reference":
        return "Having a fly.toml in your project"
    return None


def detect_fly(state: DetectionState) -> Context | None:
    """Detect Fly.io project by fly.toml file.

    Args:
        state: Detection state with environment

    Returns:
        Fly context if fly.toml exists
    """
    check_dir = state.env.pane_pwd or state.env.working_dir

    if check_dir and (check_dir / "fly.toml").exists():
        return Context(
            name="fly",
            type="deployment",
            priority=25,
            sheet="fly",
            metadata={"config": "fly.toml"},
        )

    return None
