package com.muyu.domain;

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;
import org.springframework.format.annotation.DateTimeFormat;

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

/**
 * 预警规则对象 warn_rule
 *
 * @author muyu
 * @date 2024-09-20
 */

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

    /** 规则id */
    @Schema(type = "Long",description = "规则id")
    @TableId( type = IdType.AUTO)
    private Long warnRuleId;

    /** 规则名称 */
    @Schema(type = "String",description = "规则名称")
    @Excel(name = "规则名称")
    private String ruleName;

    /** 策略id */
    @Schema(type = "Integer",description = "策略id")
    @Excel(name = "策略id")
    private Integer strategyId;

    /** 报文数据类型id */
    @Schema(type = "Integer",description = "报文数据类型id")
    @Excel(name = "报文数据类型id")
    private Integer msgTypeId;

    /** 滑窗时间 */
    @Schema(type = "Date",description = "滑窗时间")
    @Excel(name = "滑窗时间")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date slideTime;

    /** 滑窗频率 */
    @Schema(type = "Integer",description = "滑窗频率")
    @Excel(name = "滑窗频率")
    private Integer slideFrequency;

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

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

    /**
     * 策略外键id
     */
    @Schema(type = "Integer",description = "策略外键id")
    @Excel(name = "策略外键id")
    private Integer warnStrategyId;


    public static WarnRule updateBuilder(WarnRule warnRule, Supplier<Long> supplier) {
        return WarnRule.builder()
                .warnRuleId(supplier.get())
                .ruleName(warnRule.getRuleName())
                .strategyId(warnRule.getStrategyId())
                .msgTypeId(warnRule.getMsgTypeId())
                .slideTime(warnRule.getSlideTime())
                .slideFrequency(warnRule.getSlideFrequency())
                .maxValue(warnRule.getMaxValue())
                .minValue(warnRule.getMinValue())
                .build();
    }


    @Override
    public String toString() {
        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
            .append("id", getWarnRuleId())
            .append("ruleName", getRuleName())
            .append("strategyId", getStrategyId())
            .append("msgTypeId", getMsgTypeId())
            .append("slideTime", getSlideTime())
            .append("slideFrequency", getSlideFrequency())
            .append("maxValue", getMaxValue())
            .append("minValue", getMinValue())
            .toString();
    }
}
