from pydantic import BaseModel, model_validator from fiber_package.util import EntityList, GroupList, GroupRef from typing import Self 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(BaseModel): full_name_EN: str full_name_NL: str description_EN: str = "" description_NL: str = "" committee_type: CommitteeType active: bool = True editions: GroupList current_edition: GroupRef | None @model_validator(mode='after') def current_edition_in_editions(self) -> Self: uuid = self.current_edition if uuid is None: return self if uuid not in self.editions: raise ValueError("Current edition must be in list of editions") return self # TODO... maybe require that an active board always has a current_edition that is non-empty? class CommitteeEditionModel(BaseModel): members: EntityList 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.keys(): if uuid not in self.members: raise ValueError("Cannot only assign functions to members") return self