package com.muyu.domain;

import java.util.Date;
import java.util.function.Supplier;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.muyu.common.core.annotation.Excel;
import com.muyu.common.core.web.domain.BaseEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import lombok.experimental.SuperBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;

/**
 * 预警日志对象 warn_logs
 *
 * @author muyu
 * @date 2024-09-20
 */

@Data
@Setter
@Getter
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@TableName("warn_logs")
public class WarnLogs extends BaseEntity{
    private static final long serialVersionUID = 1L;

    /** 预警日志id */
    @TableId( type = IdType.AUTO)
    @Schema(type = "Long",description = "预警日志id")
    private Long warnLogsId;

    /** 车辆vin码 */
    @Schema(type = "String",description = "车辆vin码")
    @Excel(name = "车辆vin码")
    private String vin;

    /** 规则id */
    @Schema(type = "Integer",description = "规则id")
    @Excel(name = "规则id")
    private Integer warnRuleId;

    /** 开始时间 */
    @Schema(type = "Date",description = "开始时间")
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "开始时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date startTime;

    /** 结束时间 */
    @Schema(type = "Date",description = "结束时间")
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "结束时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date endTime;

    /** 最大值 */
    @Schema(type = "Integer",description = "最大值")
    @Excel(name = "最大值")
    private Integer maxValue;

    /** 最小值 */
    @Schema(type = "Integer",description = "最小值")
    @Excel(name = "最小值")
    private Integer minValue;

    /** 平均值 */
    @Schema(type = "Integer",description = "平均值")
    @Excel(name = "平均值")
    private Integer avgValue;

    /** 中位数 */
    @Schema(type = "Integer",description = "中位数")
    @Excel(name = "中位数")
    private Integer medianValue;

    /** 是否发送预警 */
    @Schema(type = "Integer",description = "是否发送预警")
    @Excel(name = "是否发送预警")
    private Integer status;

    public static WarnLogs updateBuilder(WarnLogs warnLogs, Supplier<Long> supplier) {
        return WarnLogs.builder()
                .warnLogsId(supplier.get())
                .vin(warnLogs.getVin())
                .warnRuleId(warnLogs.getWarnRuleId())
                .startTime(warnLogs.getStartTime())
                .endTime(warnLogs.getEndTime())
                .maxValue(warnLogs.getMaxValue())
                .minValue(warnLogs.getMinValue())
                .avgValue(warnLogs.getAvgValue())
                .medianValue(warnLogs.getMedianValue())
                .status(warnLogs.getStatus())
                .build();
    }


    @Override
    public String toString() {
        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
            .append("id", getWarnLogsId())
            .append("vin", getVin())
            .append("warnRuleId", getWarnRuleId())
            .append("startTime", getStartTime())
            .append("endTime", getEndTime())
            .append("maxValue", getMaxValue())
            .append("minValue", getMinValue())
            .append("avgValue", getAvgValue())
            .append("medianValue", getMedianValue())
            .append("status", getStatus())
            .toString();
    }
}
