1"""Member away date ranges.
2
3Members declare date ranges (inclusive) they'll be away on ``/account/``; the bot grants/removes the "Away on a
4Quest" role (``GuildConfig.away_role_id``) for whoever's range covers today in America/Chicago
5(``GET /api/guilds/{guild_id}/away-now``), and ``EventDetail.away`` flags members away on an event's start date.
6"""
7
8from datetime import date # pydantic needs it at runtime
9from uuid import UUID # pydantic needs it at runtime
10
11from pydantic import BaseModel, ConfigDict, Field, model_validator
12
13
[docs]
14class AwayRangeIn(BaseModel):
15 """Body for ``POST /api/me/away``."""
16
17 start_date: date
18 end_date: date
19 note: str | None = Field(default=None, max_length=100)
20
21 @model_validator(mode="after")
22 def _end_not_before_start(self) -> AwayRangeIn:
23 if self.end_date < self.start_date:
24 msg = "end_date must be on or after start_date"
25 raise ValueError(msg)
26 return self
27
28
[docs]
29class AwayRangeSchema(BaseModel):
30 """One of the signed-in member's away ranges, as returned by ``GET/POST /api/me/away``."""
31
32 model_config = ConfigDict(from_attributes=True)
33
34 id: UUID
35 start_date: date
36 end_date: date
37 note: str | None
38
39
[docs]
40class AwayNowReport(BaseModel):
41 """``GET /api/guilds/{guild_id}/away-now``: linked members away today (America/Chicago), bot-facing."""
42
43 discord_ids: list[int]