from collections.abc import Sequence from typing import Protocol, Self from apps.catalog.domain.entities import Service, ServiceUnit, WorkType from apps.catalog.domain.value_objects import CatalogName class CatalogItem(Protocol): """What service units, services and work types share: activation and ordering.""" @property def id(self) -> int | None: ... def with_active(self, active: bool) -> Self: ... class OrderedRepository[T: CatalogItem](Protocol): def get(self, item_id: int) -> T | None: ... def save(self, item: T) -> T: ... def sibling_ids(self, item: T) -> list[int]: """Ids of the rows on the same level as ``item`` (itself included), in order.""" ... def set_order(self, ids: Sequence[int]) -> None: """Renumber ``sort_order`` of these rows in the given order.""" ... class ServiceUnitRepository(OrderedRepository[ServiceUnit], Protocol): def is_name_taken(self, name: CatalogName, *, exclude_id: int | None = None) -> bool: ... def next_sort_order(self) -> int: ... class ServiceRepository(OrderedRepository[Service], Protocol): def is_name_taken( self, service_unit_id: int, name: CatalogName, *, exclude_id: int | None = None ) -> bool: ... def next_sort_order(self, service_unit_id: int) -> int: ... class WorkTypeRepository(OrderedRepository[WorkType], Protocol): def is_name_taken( self, service_unit_id: int, service_id: int | None, name: CatalogName, *, exclude_id: int | None = None, ) -> bool: ... def next_sort_order(self, service_unit_id: int, service_id: int | None) -> int: ...