Files
031-flash-card/src/flash_card/presentation/features/level/level_view_model.py
T
Tirsvad f45d6036e4 MIL-008: Choose level
Review record RC-041 (Go, autonomous mode, not independent).

Task: MIL-008#1
Task: MIL-008#2
Task: MIL-008#3
Task: MIL-008#4
Task: MIL-008#5
Task: MIL-008#6
Task: MIL-008#7
Task: MIL-008#8
2026-10-14 23:58:31 +08:00

54 lines
1.4 KiB
Python

"""View model of the level screen.
@file level_view_model.py
@brief Exposes the title and the level choices; free of any Tkinter import.
"""
from collections.abc import Sequence
from dataclasses import dataclass
from flash_card.constants import LEVEL_CHOICES, LEVEL_TITLE
from flash_card.domain.value_objects.level import Level
@dataclass(frozen=True, slots=True)
class LevelChoice:
"""One choice on the level screen."""
## @brief Text of the choice.
label: str
## @brief The level the choice stands for.
level: Level
class LevelViewModel:
"""Data the level view shows."""
def __init__(self, choices: Sequence[tuple[str, int | None]] | None = None) -> None:
"""Create the view model.
@param choices Label and word limit of each choice, or None for the
choices of the program.
"""
source = LEVEL_CHOICES if choices is None else choices
## @brief The choices in display order.
self._choices = tuple(
LevelChoice(label, Level(limit)) for label, limit in source
)
@property
def title(self) -> str:
"""Return the title of the screen.
@return The title text.
"""
return LEVEL_TITLE
@property
def choices(self) -> tuple[LevelChoice, ...]:
"""Return the choices.
@return The choices in display order.
"""
return self._choices