# ------------------------------------------------------------ # Centralised enumeration definitions for the data‑model layer. # Keeping them in one module avoids circular imports and makes # type‑checking / IDE completion straightforward. # ------------------------------------------------------------ from __future__ import annotations from enum import StrEnum from typing import Any, Iterable class ScheduleStatus(StrEnum): """ Canonical status values for a ``Schedule`` row. Using ``StrEnum`` means the enum members behave like regular strings (e.g. they can be written directly to SQLite) while still giving us the safety and autocomplete of an enum. """ PENDING = "pending" ACCEPTED = "accepted" DECLINED = "declined" @classmethod def from_raw(cls, value: Any) -> "ScheduleStatus": """ Convert an arbitrary value (often a plain string coming from the DB) into a ``ScheduleStatus`` member. Raises ------ ValueError If the value does not correspond to any defined member. """ if isinstance(value, cls): return value try: # ``cls(value)`` works because ``StrEnum`` subclasses ``str``. return cls(value) except ValueError as exc: raise ValueError(f"Invalid ScheduleStatus: {value!r}") from exc