"""
Pydantic schemas for RSS articles.

This module defines request and response schemas for RSS article-related operations.
"""

from datetime import datetime
from typing import Optional

from pydantic import BaseModel, Field, ConfigDict


class RSSArticleBase(BaseModel):
    """Base schema for RSS article data."""
    article_id: str = Field(..., description="Unique identifier from RSS feed")
    title: str = Field(..., min_length=1, max_length=500, description="Article title")
    content: Optional[str] = Field(None, description="Article content/description")
    published_at: datetime = Field(..., description="Timestamp when article was published")
    source_url: str = Field(..., min_length=1, max_length=1000, description="URL of RSS feed source")
    match_id: Optional[int] = Field(None, description="Foreign key to matches table")
    source: str = Field(default="rss", description="Source feed name")


class RSSArticleCreate(RSSArticleBase):
    """Schema for creating a new RSS article."""
    pass


class RSSArticleResponse(RSSArticleBase):
    """Schema for RSS article response."""
    id: int = Field(..., description="Primary key")
    model_config = ConfigDict(from_attributes=True)


class RSSArticleListResponse(BaseModel):
    """Schema for a list of RSS articles."""
    data: list[RSSArticleResponse]
    count: int = Field(..., description="Total number of articles")
    meta: dict = Field(default_factory=dict, description="Additional metadata")


class RSSArticleStatsResponse(BaseModel):
    """Schema for RSS article statistics."""
    total_articles: int = Field(..., description="Total number of articles")
    articles_by_source: dict = Field(..., description="Breakdown by source feed")
    articles_by_match: dict = Field(..., description="Breakdown by match")
