"""Medical record validators — Phase 13.5."""
from __future__ import annotations

from app.models.types import EncounterStatus
from shared.exceptions import AppError


def ensure_encounter_mutable(status: EncounterStatus) -> None:
    if status == EncounterStatus.FINALIZED:
        raise AppError(
            "Encounter finalized — immutable",
            status_code=409,
            error_code="encounter_finalized",
        )


def ensure_encounter_can_finalize(status: EncounterStatus) -> None:
    if status == EncounterStatus.FINALIZED:
        raise AppError(
            "Encounter already finalized",
            status_code=409,
            error_code="encounter_already_finalized",
        )
    if status not in (EncounterStatus.DRAFT, EncounterStatus.IN_PROGRESS):
        raise AppError(
            "Encounter cannot be finalized from current status",
            status_code=409,
            error_code="invalid_encounter_finalize",
        )
