"""Manage the cached setup completion flag stored on application state."""

from __future__ import annotations

from typing import TYPE_CHECKING

from app.utils.runtime_state import get_runtime_state

if TYPE_CHECKING:  # pragma: no cover
    from fastapi import FastAPI


def is_setup_complete_cached(app: FastAPI) -> bool:
    """Return the cached setup completion state from the runtime state manager."""
    return get_runtime_state(app).setup_complete_cached


def set_setup_complete_cache(app: FastAPI, completed: bool) -> None:
    """Set the cached setup completion state on the runtime state manager."""
    get_runtime_state(app).setup_complete_cached = completed


def invalidate_setup_complete_cache(app: FastAPI) -> None:
    """Reset the cached setup completion state.

    This helper exists so the cache can be invalidated explicitly if the
    application state changes during runtime.
    """
    get_runtime_state(app).setup_complete_cached = False
