package com.muyu.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.muyu.domain.req.FaultConditionAddReq;
import com.muyu.domain.req.FaultConditionUpdReq;
import com.muyu.domain.resp.FaultConditionTotalListResp;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import java.math.BigDecimal;
import java.util.function.Supplier;

/**
 * 故障规则
 * @Author：weiran
 * @Package：com.muyu.cloud.faultmanage.domain
 * @Project：cloud-server-8
 * @name：FaultCondition
 * @Date：2024/9/21 19:51
 */

@Data
@AllArgsConstructor
@NoArgsConstructor
@SuperBuilder
@TableName(value = "car_fault_condition",autoResultMap = true)
@Tag(name = "故障规则")
public class FaultCondition {
    /**
     * 故障规则表Id
     */
    @TableId(value = "carcondition_id",type = IdType.AUTO)
    private Long carconditionId;
    /**
     * 车辆类型Id
     */
    private Long carTypeId;
    /**
     *故障名称Id
     */
    private long messageTypeId;
    /**
     * 故障条件
     */
    private String faultconditionIdentification;
    /**
     * 故障规则参数
     */
    private BigDecimal faultconditionParameter;
    /**
     * 车辆类型名称
     */
    @TableField(exist = false)
    private String carTypeName;
    /**
     * 故障名称
     */
    @TableField(exist = false)
    private String messageTypeName;
    /**
     * 报文编码
     */
    @TableField(exist = false)
    private String messageTypeCode;


    public static FaultCondition faultConditionadd(FaultConditionAddReq faultConditionAddReq){
        return FaultCondition.builder()
                .carTypeId(faultConditionAddReq.getCarTypeId())
                .messageTypeId(faultConditionAddReq.getMessageTypeId())
                .faultconditionIdentification(faultConditionAddReq.getFaultconditionIdentification())
                .faultconditionParameter(faultConditionAddReq.getFaultconditionParameter())
                .build();
    }

    public static FaultCondition faultConditionupd(FaultConditionUpdReq faultConditionUpdReq, Supplier<Long> idSupplier){
        return FaultCondition.builder()
                .carconditionId(faultConditionUpdReq.getCarconditionId())
                .carTypeId(faultConditionUpdReq.getCarTypeId())
                .messageTypeId(faultConditionUpdReq.getMessageTypeId())
                .faultconditionIdentification(faultConditionUpdReq.getFaultconditionIdentification())
                .faultconditionParameter(faultConditionUpdReq.getFaultconditionParameter())
                .build();
    }


    public static FaultCondition faultConditionBuilder(FaultCondition faultCondition) {
        return FaultCondition.builder()
                .carconditionId(faultCondition.getCarconditionId())
                .carTypeId(faultCondition.getCarTypeId())
                .messageTypeId(faultCondition.getMessageTypeId())
                .build();
    }
}
