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.FaultCodeAddReq;
import com.muyu.domain.req.FaultCodeUpdReq;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

/**
 * @Author：weiran
 * @Package：com.muyu.cloud.faultmanage.domain
 * @Project：cloud-faultmanage
 * @name：FaultCode
 * @Date：2024/9/17 14:55
 */
/**
 * 故障码
 *
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@SuperBuilder
@TableName(value = "car_faultcode",autoResultMap = true)
@Tag(name = "故障码")
public class FaultCode {

    /**
     *故障码Id
     */
    @TableId(value = "faultcode_id",type = IdType.AUTO)
    private Long faultcodeId;
    /**
     *故障名称Id
     */
    private long messageTypeId;
    /**
     *故障码
     */
    private String faultcodeNumber;
    /**
     *故障组
     */
    private String faultGroup;
    /**
     *故障位
     */
    private String faultBit;
    /**
     *故障值
     */
    private String faultValue;
    /**
     *是否警告
     */
    private Integer isWarning;
    /**
     *故障类型名称
     */
    @TableField(exist = false)
    private String faulttypeName;
    /**
     * 故障名称
     */
    @TableField(exist = false)
    private String messageTypeName;
    /**
     * 报文编码
     */
    @TableField(exist = false)
    private String messageTypeCode;
    /**
     *报文所属类别
     */
    @TableField(exist = false)
    private String messageTypeBelongs;


    public static FaultCode addfaultcode(FaultCodeAddReq faultCodeAddReq){
        return FaultCode.builder()
                .faultcodeId(faultCodeAddReq.getFaultcodeId())
                .messageTypeId(faultCodeAddReq.getMessageTypeId())
                .faultcodeNumber(faultCodeAddReq.getFaultcodeNumber())
                .faultGroup(faultCodeAddReq.getFaultGroup())
                .faultBit(faultCodeAddReq.getFaultBit())
                .faultValue(faultCodeAddReq.getFaultValue())
                .isWarning(faultCodeAddReq.getIsWarning())
                .build();
    }

    public static FaultCode updfaultcode(FaultCodeUpdReq faultCodeUpdReq){
        return FaultCode.builder()
                .faultcodeId(0L)
                .messageTypeId(faultCodeUpdReq.getMessageTypeId())
                .faultcodeNumber(faultCodeUpdReq.getFaultcodeNumber())
                .faultGroup(faultCodeUpdReq.getFaultGroup())
                .faultBit(faultCodeUpdReq.getFaultBit())
                .faultValue(faultCodeUpdReq.getFaultValue())
                .isWarning(faultCodeUpdReq.getIsWarning())
                .build();
    }


    public static FaultCode faultCodeBuilder(FaultCode faultCode) {
        return FaultCode.builder()
                .faultcodeId(faultCode.getFaultcodeId())
                .messageTypeId(faultCode.getMessageTypeId())
                .faultcodeNumber(faultCode.getFaultcodeNumber())
                .faultGroup(faultCode.faultGroup)
                .faultBit(faultCode.faultBit)
                .faultValue(faultCode.faultValue)
                .isWarning(faultCode.isWarning)
                .build();
    }
}
