"""Pydantic schemas for CoordMessage."""

from datetime import datetime
from typing import Optional
from uuid import UUID

from pydantic import BaseModel, Field


class CoordMessageCreate(BaseModel):
    """Input schema for sending a message."""

    from_session: str = Field(..., description="Sending session identifier", max_length=200)
    to_session: Optional[str] = Field(None, description="Recipient session; NULL = broadcast", max_length=200)
    project_key: Optional[str] = Field(None, description="Optional project context", max_length=200)
    subject: str = Field(..., description="Message subject", max_length=500)
    body: str = Field(..., description="Message body, markdown ok")


class CoordMessageUpdate(BaseModel):
    """Input schema for updating a message (mark read, etc.)."""

    read_at: Optional[datetime] = None


class CoordMessageResponse(BaseModel):
    """Output schema for a message."""

    id: UUID
    from_session: str
    to_session: Optional[str]
    project_key: Optional[str]
    subject: str
    body: str
    read_at: Optional[datetime]
    created_at: datetime
    updated_at: datetime

    model_config = {"from_attributes": True}
