from dataclasses import dataclass, field from enum import StrEnum from pydantic import BaseModel class ChatKind(StrEnum): DM = "dm" GROUP = "group" CHANNEL = "channel" class ScopeType(StrEnum): DEFAULT_DM = "default_dm" DEFAULT_GROUP = "default_group" DEFAULT_CHANNEL = "default_channel" FOLDER = "folder" CHAT = "chat" DEFAULT_SCOPE_BY_KIND: dict[ChatKind, ScopeType] = { ChatKind.DM: ScopeType.DEFAULT_DM, ChatKind.GROUP: ScopeType.DEFAULT_GROUP, ChatKind.CHANNEL: ScopeType.DEFAULT_CHANNEL, } KIND_BY_DEFAULT_SCOPE: dict[ScopeType, ChatKind] = { scope: kind for kind, scope in DEFAULT_SCOPE_BY_KIND.items() } class CaptureToggles(BaseModel): messages: bool = False media: bool = False self_destruct_media: bool = False stt: bool = False reactions: bool = False track_edits_deletes: bool = False profile_history: bool = False stories: bool = False presence: bool = False backfill: bool = False class PolicyCreate(CaptureToggles): account_id: int | None = None scope_type: ScopeType scope_id: int | None = None class PolicyRecord(CaptureToggles): id: int account_id: int | None scope_type: ScopeType scope_id: int | None @dataclass(slots=True) class ChatMeta: chat_id: int kind: ChatKind is_bot: bool = False is_contact: bool | None = None @dataclass(slots=True) class FolderSpec: folder_id: int order_index: int title: str include_ids: set[int] = field(default_factory=set) exclude_ids: set[int] = field(default_factory=set) pinned_ids: set[int] = field(default_factory=set) contacts: bool = False non_contacts: bool = False groups: bool = False broadcasts: bool = False bots: bool = False is_chatlist: bool = False class PolicyParent(BaseModel): scope_type: ScopeType scope_id: int | None title: str | None = None toggles: CaptureToggles class PolicyRuleView(PolicyRecord): title: str | None = None parent: PolicyParent | None = None class PolicyScopeView(BaseModel): title: str | None rule: PolicyRecord | None parent: PolicyParent | None @dataclass(slots=True) class PolicySet: chat: dict[int, CaptureToggles] = field(default_factory=dict) folder: dict[int, CaptureToggles] = field(default_factory=dict) defaults: dict[ChatKind, CaptureToggles] = field(default_factory=dict)