from datetime import date, datetime
from typing import Optional

from pydantic import BaseModel, Field


class ResourcesMaterialQuery(BaseModel):
    advertiser_id: Optional[str] = Field(None, description="广告主id")
    material_id: Optional[str] = Field(None, description="素材id")
    upload_id: Optional[str] = Field(None, description="上传资源平台id")
    resource_type: Optional[str] = Field(None, description="资源类型，image或者video")
    page: int = Field(1, description="页码")
    page_size: int = Field(20, description="每页数量")


class GeneratedResourceOut(BaseModel):
    file_name: Optional[str] = Field(None, description="文件名")
    resource_url: str = Field(..., description="资源URL")
    remote_url: Optional[str] = Field(None, description="远程URL")
    storage_type: str = Field(..., description="存储类型")
    storage_path: Optional[str] = Field(None, description="存储路径")
    file_size_bytes: int = Field(..., description="文件大小（字节）")
    source_model: str = Field(..., description="来源模型")
    source_model_module: Optional[str] = Field(None, description="来源模型模块")
    source_id: str = Field(..., description="来源id")
    engine_id: Optional[str] = Field(None, description="引擎id")
    engine_type: Optional[str] = Field(None, description="引擎类型")
    provider: Optional[str] = Field(None, description="提供商")
    model_name: Optional[str] = Field(None, description="模型名称")
    generated_at: Optional[datetime] = Field(None, description="生成时间")
    resource_month: date = Field(..., description="资源月份")
    created_at: datetime = Field(..., description="创建时间")


class ResourcesMaterialOut(BaseModel):
    id: str = Field(..., description="主键")
    oauth_id: str = Field(..., description="授权表user_oauth自增id")
    advertiser_id: Optional[str] = Field(None, description="广告主id")
    target_table: Optional[str] = Field(None, description="资源表名称")
    target_id: Optional[str] = Field(None, description="资源表id")
    material_id: Optional[str] = Field(None, description="素材id")
    upload_id: Optional[str] = Field(None, description="上传资源平台id")
    resource_type: Optional[str] = Field(None, description="资源类型")
    user_id: Optional[str] = Field(None, description="用户登录id")
    task_id: Optional[str] = Field(None, description="前测任务id")
    note: Optional[str] = Field(None, description="备注")
    status: Optional[str] = Field(None, description="前测状态")
    pre_result: Optional[str] = Field(None, description="前测结果")
    pre_test_template_id: Optional[str] = Field(None, description="前测模板id")
    created_at: datetime = Field(..., description="创建时间")
    updated_at: datetime = Field(..., description="更新时间")
    resource: Optional[GeneratedResourceOut] = Field(None, description="关联的资源信息")


class ResourcesMaterialListResponse(BaseModel):
    code: int = Field(0, description="返回码，0表示成功")
    message: str = Field("查询成功", description="返回消息")
    data: list[ResourcesMaterialOut] = Field(..., description="素材列表数据")
    total: int = Field(..., description="总记录数")