from pydantic import BaseModel, Field


class MPCParamsSchema(BaseModel):
    P: int = Field(default=20, ge=5, le=100, description='预测时域')
    M: int = Field(default=5, ge=1, le=20, description='控制时域')
    Q: float = Field(default=10.0, gt=0, description='跟踪误差权重')
    R: float = Field(default=0.1, gt=0, description='控制增量权重')
    alpha: float = Field(default=0.8, gt=0, lt=1, description='参考轨迹柔化系数')
    u_min: float = Field(default=0.0, description='电流下限(A)')
    u_max: float = Field(default=10.0, description='电流上限(A)')
    du_min: float = Field(default=-2.0, description='电流增量下限(A/步)')
    du_max: float = Field(default=2.0, description='电流增量上限(A/步)')
    y_min: float = Field(default=-50.0, description='温度约束下限(°C)')
    y_max: float = Field(default=200.0, description='温度约束上限(°C)')
    correction_gain: float = Field(default=0.5, ge=0, le=1, description='反馈校正增益')


class CreateExperimentRequest(BaseModel):
    name: str = Field(min_length=1, max_length=255)
    model_id: int
    input_csv_path: str = Field(min_length=1, description='读取传感器数据的CSV文件路径')
    output_csv_path: str = Field(min_length=1, description='输出曲线数据的CSV文件路径')
    target_temp: float = Field(description='目标温度(°C)')
    sampling_interval: float = Field(default=1.0, gt=0, le=3600, description='采样周期(秒)')
    mpc_params: MPCParamsSchema = Field(default_factory=MPCParamsSchema)
