from pydantic import BaseModel, ConfigDict, Field

from app.schemas.common import NaiveDatetime


class CreditRatioCreate(BaseModel):
    model_config_id: str = Field(
        ...,
        max_length=32,
        description=(
            "引擎ID，兼容旧字段名。gen_type=image 时填写 image_engines.id；"
            "gen_type=video 时填写 video_engines.id。当前不再绑定 model_configs.id 外键"
        ),
        examples=["engine_xxx"],
    )
    gen_type: str = Field(
        default="video",
        max_length=16,
        description="生成类型：image=图片积分规则，video=视频积分规则",
        examples=["video"],
    )
    resolution: str = Field(
        ...,
        max_length=16,
        description="计费参数。视频为分辨率，例如 480p/720p/1080p；图片为分辨率档位，例如 2K/4K",
        examples=["720p"],
    )
    ratio: float = Field(
        ...,
        gt=0,
        description="积分倍率。最终扣费会乘以该倍率",
        examples=[1.0],
    )
    base_credits: float = Field(
        default=80.0,
        ge=0,
        description="基础积分。视频按 base_credits + per_second_credits * duration 后再乘 ratio；图片按 base_credits * ratio",
        examples=[80.0],
    )
    per_second_credits: float = Field(
        default=2.0,
        ge=0,
        description="视频每秒积分。图片规则通常为 0",
        examples=[2.0],
    )


class CreditRatioOut(CreditRatioCreate):
    id: str = Field(..., description="积分规则ID")
    created_at: NaiveDatetime = Field(..., description="创建时间")

    model_config = ConfigDict(from_attributes=True)
