from pydantic import BaseModel, Field, ConfigDict
from schemas.base import NewsItemBase


class FavoriteCheckResponse(BaseModel):
    is_favorite: bool = Field(..., alias = "isFavorite")

class FavoriteAddRequest(BaseModel):
    newsId: int

# 规划两个类：一个是新闻模型类 + 收藏模型类
class FavoriteNewsItemResponse(NewsItemBase):
    favorite_id: int = Field(alias = "favoriteId")
    favorite_time: datetime = Field(alias = "favoriteTime")

    model_config = ConfigDict(
        populate_by_name=True,   # 字段名与属性名一致
        from_attributes= True   # 模型类属性(允许从 ORM 对象属性中取值)
    )


# 收藏列表接口响应模型类
class FavoriteListResponse(BaseModel):
    list: list[FavoriteNewsItemResponse]
    total: int
    has_more: bool = Field(alias = "hasMore")
    model_config = ConfigDict(
        populate_by_name=True,   # 字段名与属性名一致
        from_attributes= True   # 模型类属性(允许从 ORM 对象属性中取值)
    )