from pydantic import model_validator, UUID7 from fiber_package.refs import ( CommitteeEditionRef, CommitteeEditionRefList, EntityRefList ) from fiber_package.base import FiberBaseModel from typing import Self, Literal from datetime import date from .enums import CommitteeType ''' Committees are groups of members for a definite period. Every committee has a list of editions. An edition is a definite group of members with functions and a timespan. ''' class CommitteeModel(FiberBaseModel): collection_name: Literal["committee"] = "committee" full_name_en: str full_name_nl: str description_en: str = "" description_nl: str = "" committee_type: CommitteeType active: bool = True editions: CommitteeEditionRefList current_edition: CommitteeEditionRef | None @model_validator(mode='after') def current_edition_in_editions(self) -> Self: if self.current_edition is None: return self uuid = self.current_edition.uuid if uuid not in self.editions: raise ValueError("Current edition must be in list of editions") return self class CommitteeEditionModel(FiberBaseModel): collection_name: Literal["committee_edition"] = "committee_edition" members: EntityRefList functions: dict[UUID7, str] start_date: date end_date: date | None # None means ongoing @model_validator(mode='after') def functions_to_members_only(self) -> Self: for uuid in self.functions: if uuid not in self.members: raise ValueError("Cannot only assign functions to committee members") return self