"""Request, response, and patch schemas for Telegram messages."""
from __future__ import annotations

from datetime import datetime
from typing import Any

from repo_core.base.schemas import (
    BaseRequestSchema,
    BaseResponseSchema,
    BasePatchSchema,
)


class CreateTelegramMessageRequest(BaseRequestSchema):
    """Validated payload for persisting a new Telegram message record."""

    message_id: int
    peer_id: int
    date: int
    message: str = ""

    out: bool = False
    mentioned: bool = False
    media_unread: bool = False
    silent: bool = False
    post: bool = False
    from_scheduled: bool = False
    legacy: bool = False
    edit_hide: bool = False
    pinned: bool = False
    noforwards: bool = False
    invert_media: bool = False

    offline: bool = False
    paid_suggested_post_stars: bool = False
    paid_suggested_post_ton: bool = False

    from_id: dict[str, Any] | None = None
    from_boosts_applied: int | None = None
    saved_peer_id: dict[str, Any] | None = None
    fwd_from: dict[str, Any] | None = None
    via_bot_id: int | None = None
    via_business_bot_id: int | None = None
    reply_to: dict[str, Any] | None = None
    media: dict[str, Any] | None = None
    reply_markup: dict[str, Any] | None = None
    details: list[dict[str, Any]] | None = None
    views: int | None = None
    forwards: int | None = None
    replies: dict[str, Any] | None = None
    edit_date: int | None = None
    post_author: str | None = None
    grouped_id: int | None = None
    reactions: dict[str, Any] | None = None
    restriction_reason: list[dict[str, Any]] | None = None
    ttl_period: int | None = None
    quick_reply_shortcut_id: int | None = None
    effect: dict[str, Any] | None = None
    factcheck: dict[str, Any] | None = None
    report_delivery_until_date: int | None = None
    paid_message_stars: int | None = None
    suggested_post: dict[str, Any] | None = None


class PatchTelegramMessageRequest(BasePatchSchema):
    """Partial update payload for an existing Telegram message record."""

    message: str | None = None
    media_unread: bool | None = None
    silent: bool | None = None
    pinned: bool | None = None
    noforwards: bool | None = None
    edit_hide: bool | None = None
    media: dict[str, Any] | None = None
    reply_markup: dict[str, Any] | None = None
    details: list[dict[str, Any]] | None = None
    views: int | None = None
    forwards: int | None = None
    edit_date: int | None = None
    reactions: dict[str, Any] | None = None
    effect: dict[str, Any] | None = None
    factcheck: dict[str, Any] | None = None


class TelegramMessageResponse(BaseResponseSchema):
    """Serialised Telegram message returned to API callers."""

    message_id: int
    peer_id: int
    date: int
    message: str

    out: bool = False
    mentioned: bool = False
    media_unread: bool = False
    silent: bool = False
    post: bool = False
    from_scheduled: bool = False
    legacy: bool = False
    edit_hide: bool = False
    pinned: bool = False
    noforwards: bool = False
    invert_media: bool = False

    offline: bool = False
    paid_suggested_post_stars: bool = False
    paid_suggested_post_ton: bool = False

    from_id: dict[str, Any] | None = None
    from_boosts_applied: int | None = None
    saved_peer_id: dict[str, Any] | None = None
    fwd_from: dict[str, Any] | None = None
    via_bot_id: int | None = None
    via_business_bot_id: int | None = None
    reply_to: dict[str, Any] | None = None
    media: dict[str, Any] | None = None
    reply_markup: dict[str, Any] | None = None
    details: list[dict[str, Any]] | None = None
    views: int | None = None
    forwards: int | None = None
    replies: dict[str, Any] | None = None
    edit_date: int | None = None
    post_author: str | None = None
    grouped_id: int | None = None
    reactions: dict[str, Any] | None = None
    restriction_reason: list[dict[str, Any]] | None = None
    ttl_period: int | None = None
    quick_reply_shortcut_id: int | None = None
    effect: dict[str, Any] | None = None
    factcheck: dict[str, Any] | None = None
    report_delivery_until_date: int | None = None
    paid_message_stars: int | None = None
    suggested_post: dict[str, Any] | None = None

    created_at: datetime | None = None
    updated_at: datetime | None = None
