# -*- coding: utf-8 -*-

from pydantic import BaseModel, ConfigDict, Field
from fastapi import Query

from app.core.validator import DateTimeStr
from app.core.base_schema import BaseSchema, UserBySchema

class BizMecCreateSchema(BaseModel):
    """
    机构信息新增模型
    """
    crane_no: str = Field(default=..., description='起重机编号 ')
    mec_no: str = Field(default=..., description='机构编号 ')
    mec_category: str = Field(default=..., description='机构分类 MecCategory')
    mec_type: str = Field(default=..., description='机构类型 MecType')
    hoist_weight: str | None = Field(default=None, description='起升重量 起升机构')
    hoist_height: str | None = Field(default=None, description='起升高度 起升机构')
    hoist_speed: str | None = Field(default=None, description='起升速度 起升机构')
    rope_count: str | None = Field(default=None, description='钢线绳受力根数 起升机构')
    rope_max_pull: str | None = Field(default=None, description='钢丝绳最大拉力 起升机构')
    rope_diameter: str | None = Field(default=None, description='钢丝绳直径 起升机构')
    rope_model: str | None = Field(default=None, description='钢丝绳型号 起升机构')
    car_speed: str | None = Field(default=None, description='速度 平移机构')
    wheel_span: str | None = Field(default=None, description='轮距 平移机构')
    track_span: str | None = Field(default=None, description='轨距 平移机构')
    wheel_pressure: str | None = Field(default=None, description='轮压 平移机构')
    track_model: str | None = Field(default=None, description='轨道型号 平移机构')
    track_diameter: str | None = Field(default=None, description='车轨直径 平移机构')
    track_count: str | None = Field(default=None, description='车轨数量 平移机构')
    word_system: str | None = Field(default=None, description='工作制度 ')
    reducer_model: str | None = Field(default=None, description='减速机型号 ')
    reducer_trans_ratio: str | None = Field(default=None, description='减速机传动比 ')
    reducer_total_trans_ratio: str | None = Field(default=None, description='减速机总传动比 ')
    motor_model: str | None = Field(default=None, description='电机型号 ')
    motor_voltage: str | None = Field(default=None, description='电机额定电压 ')
    motor_current: str | None = Field(default=None, description='电机额定电流 ')
    motor_power: str | None = Field(default=None, description='电机额定功率 ')
    motor_speed: str | None = Field(default=None, description='电机转速 ')
    motor_count: str | None = Field(default=None, description='电机数量 ')
    bradk_model: str | None = Field(default=None, description='制动器型号 ')
    brake_torque: str | None = Field(default=None, description='制动器制动力矩 ')
    brake_wheel_diameter: str | None = Field(default=None, description='制动器轮径 ')
    brake_count: str | None = Field(default=None, description='制动器数量 ')
    sort: int = Field(default=..., description='排序 ')
    status: str = Field(default="1", description='是否启用(0:禁用 1:启用)')
    description: str | None = Field(default=None, max_length=255, description='备注/描述')
    hoist_weight_var_code: str | None = Field(default=None, description='重量关联变量')
    stroke_var_code: str | None = Field(default=None, description='行程高度变量')
    is_canvas_show: str | None = Field(default="0", description='是否首页动画展示')
    is_canvas_move: str | None = Field(default="0", description='是否启用动画')
    gear_select_var_codes: str | None = Field(default=None, description='机构选择变量')
    vib_gear_value: int | None = Field(default=None, description='振动分析挡位')


class BizMecUpdateSchema(BizMecCreateSchema):
    """
    机构信息更新模型
    """
    ...


class BizMecOutSchema(BizMecCreateSchema, BaseSchema):
    """
    机构信息响应模型
    """
    model_config = ConfigDict(from_attributes=True)


class BizMecQueryParam:
    """机构信息查询参数"""

    def __init__(
        self,
        hoist_weight: str | None = Query(None, description="起升重量 起升机构"),
        hoist_height: str | None = Query(None, description="起升高度 起升机构"),
        hoist_speed: str | None = Query(None, description="起升速度 起升机构"),
        rope_count: str | None = Query(None, description="钢线绳受力根数 起升机构"),
        rope_max_pull: str | None = Query(None, description="钢丝绳最大拉力 起升机构"),
        rope_diameter: str | None = Query(None, description="钢丝绳直径 起升机构"),
        rope_model: str | None = Query(None, description="钢丝绳型号 起升机构"),
        car_speed: str | None = Query(None, description="速度 平移机构"),
        wheel_span: str | None = Query(None, description="轮距 平移机构"),
        track_span: str | None = Query(None, description="轨距 平移机构"),
        wheel_pressure: str | None = Query(None, description="轮压 平移机构"),
        track_model: str | None = Query(None, description="轨道型号 平移机构"),
        track_diameter: str | None = Query(None, description="车轨直径 平移机构"),
        track_count: str | None = Query(None, description="车轨数量 平移机构"),
        word_system: str | None = Query(None, description="工作制度 "),
        reducer_model: str | None = Query(None, description="减速机型号 "),
        reducer_trans_ratio: str | None = Query(None, description="减速机传动比 "),
        reducer_total_trans_ratio: str | None = Query(None, description="减速机总传动比 "),
        motor_model: str | None = Query(None, description="电机型号 "),
        motor_voltage: str | None = Query(None, description="电机额定电压 "),
        motor_current: str | None = Query(None, description="电机额定电流 "),
        motor_power: str | None = Query(None, description="电机额定功率 "),
        motor_speed: str | None = Query(None, description="电机转速 "),
        motor_count: str | None = Query(None, description="电机数量 "),
        bradk_model: str | None = Query(None, description="制动器型号 "),
        brake_torque: str | None = Query(None, description="制动器制动力矩 "),
        brake_wheel_diameter: str | None = Query(None, description="制动器轮径 "),
        brake_count: str | None = Query(None, description="制动器数量 "),
        status: str | None = Query(None, description="是否启用(0:启用 1:禁用)"),
        hoist_weight_var_code: str | None = Query(None, description="重量关联变量"),
        stroke_var_code: str | None = Query(None, description="行程高度变量"),
        is_canvas_show: str | None = Query(None, description="是否首页动画展示"),
        is_canvas_move: str | None = Query(None, description="是否启用动画"),
        gear_select_var_codes: str | None = Query(None, description="机构选择变量"),
        crane_no: str | None = Query(None, description="起重机编号 "),
        mec_no: str | None = Query(None, description="机构编号 "),
        mec_category: str | None = Query(None, description="机构分类 MecCategory"),
        mec_type: str | None = Query(None, description="机构类型 MecType"),
        sort: int | None = Query(None, description="排序 "),
        vib_gear_value: int | None = Query(None, description="振动分析挡位"),
        created_time: list[DateTimeStr] | None = Query(None, description="创建时间范围", examples=["2025-01-01 00:00:00", "2025-12-31 23:59:59"]),
        updated_time: list[DateTimeStr] | None = Query(None, description="更新时间范围", examples=["2025-01-01 00:00:00", "2025-12-31 23:59:59"]),
        
    ) -> None:
        
        # 精确查询字段
        self.crane_no = crane_no
        # 精确查询字段
        self.mec_no = mec_no
        # 精确查询字段
        self.mec_category = mec_category
        # 精确查询字段
        self.mec_type = mec_type
        # 模糊查询字段
        self.hoist_weight = ("like", hoist_weight)
        # 模糊查询字段
        self.hoist_height = ("like", hoist_height)
        # 模糊查询字段
        self.hoist_speed = ("like", hoist_speed)
        # 模糊查询字段
        self.rope_count = ("like", rope_count)
        # 模糊查询字段
        self.rope_max_pull = ("like", rope_max_pull)
        # 模糊查询字段
        self.rope_diameter = ("like", rope_diameter)
        # 模糊查询字段
        self.rope_model = ("like", rope_model)
        # 模糊查询字段
        self.car_speed = ("like", car_speed)
        # 模糊查询字段
        self.wheel_span = ("like", wheel_span)
        # 模糊查询字段
        self.track_span = ("like", track_span)
        # 模糊查询字段
        self.wheel_pressure = ("like", wheel_pressure)
        # 模糊查询字段
        self.track_model = ("like", track_model)
        # 模糊查询字段
        self.track_diameter = ("like", track_diameter)
        # 模糊查询字段
        self.track_count = ("like", track_count)
        # 模糊查询字段
        self.word_system = ("like", word_system)
        # 模糊查询字段
        self.reducer_model = ("like", reducer_model)
        # 模糊查询字段
        self.reducer_trans_ratio = ("like", reducer_trans_ratio)
        # 模糊查询字段
        self.reducer_total_trans_ratio = ("like", reducer_total_trans_ratio)
        # 模糊查询字段
        self.motor_model = ("like", motor_model)
        # 模糊查询字段
        self.motor_voltage = ("like", motor_voltage)
        # 模糊查询字段
        self.motor_current = ("like", motor_current)
        # 模糊查询字段
        self.motor_power = ("like", motor_power)
        # 模糊查询字段
        self.motor_speed = ("like", motor_speed)
        # 模糊查询字段
        self.motor_count = ("like", motor_count)
        # 模糊查询字段
        self.bradk_model = ("like", bradk_model)
        # 模糊查询字段
        self.brake_torque = ("like", brake_torque)
        # 模糊查询字段
        self.brake_wheel_diameter = ("like", brake_wheel_diameter)
        # 模糊查询字段
        self.brake_count = ("like", brake_count)
        # 精确查询字段
        self.sort = sort
        # 模糊查询字段
        self.status = ("like", status)
        # 模糊查询字段
        self.hoist_weight_var_code = ("like", hoist_weight_var_code)
        # 模糊查询字段
        self.stroke_var_code = ("like", stroke_var_code)
        # 模糊查询字段
        self.is_canvas_show = ("like", is_canvas_show)
        # 模糊查询字段
        self.is_canvas_move = ("like", is_canvas_move)
        # 模糊查询字段
        self.gear_select_var_codes = ("like", gear_select_var_codes)
        # 精确查询字段
        self.vib_gear_value = vib_gear_value
        # 时间范围查询
        if created_time and len(created_time) == 2:
            self.created_time = ("between", (created_time[0], created_time[1]))
        if updated_time and len(updated_time) == 2:
            self.updated_time = ("between", (updated_time[0], updated_time[1]))
