"""Schemas for communications-related endpoints.""" from datetime import datetime from typing import Literal, Optional from ninja import ModelSchema, Schema from apps.blog.api.schemas import AuthorSchema from apps.communications.models import Announcement, PushNotificationDevice class AnnouncementSchema(ModelSchema): author: AuthorSchema content_html: str class Config: model = Announcement model_fields = [ "id", "title", "content", "announcement_type", "priority", "is_published", "publish_date", "created_at", "updated_at", ] @staticmethod def resolve_content_html(obj): return obj.content_html class AnnouncementListSchema(Schema): id: int title: str content: str announcement_type: str priority: str author: AuthorSchema is_published: bool publish_date: Optional[datetime] = None created_at: datetime class AnnouncementCreateSchema(Schema): title: str content: str announcement_type: Literal["general", "event", "academic", "urgent"] = "general" priority: Literal["low", "normal", "high", "urgent"] = "normal" is_published: bool = False publish_date: Optional[datetime] = None class AnnouncementUpdateSchema(Schema): title: Optional[str] = None content: Optional[str] = None announcement_type: Optional[Literal["general", "event", "academic", "urgent"]] = None priority: Optional[Literal["low", "normal", "high", "urgent"]] = None is_published: Optional[bool] = None publish_date: Optional[datetime] = None class PushDeviceSchema(ModelSchema): user: AuthorSchema class Config: model = PushNotificationDevice model_fields = ["id", "device_token", "device_type", "is_active", "created_at"] class PushDeviceCreateSchema(Schema): device_token: str device_type: str = "web" class PushDeviceUpdateSchema(Schema): is_active: bool class MessageResponseSchema(Schema): message: str success: bool = True class AnnouncementStatsSchema(Schema): total_announcements: int published_announcements: int draft_announcements: int urgent_announcements: int