package com.ruoyi.credit.domain;

import java.util.Date;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Min;
import javax.validation.constraints.Max;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.DecimalMax;
import javax.validation.constraints.Size;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;

/**
 * 验证统计信息对象 dc_validation_statistics
 * 
 * @author ruoyi
 * @date 2025-12-30
 */
public class ValidationStatistics extends BaseEntity
{
    private static final long serialVersionUID = 1L;

    /** 统计ID */
    private Long statisticsId;

    /** 统计日期 */
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    @Excel(name = "统计日期", width = 30, dateFormat = "yyyy-MM-dd")
    @NotNull(message = "统计日期不能为空")
    private Date statisticsDate;

    /** 总验证次数 */
    @Excel(name = "总验证次数")
    @NotNull(message = "总验证次数不能为空")
    @Min(value = 0, message = "总验证次数不能小于0")
    private Integer totalValidations;

    /** 通过验证次数 */
    @Excel(name = "通过验证次数")
    @NotNull(message = "通过验证次数不能为空")
    @Min(value = 0, message = "通过验证次数不能小于0")
    private Integer passedValidations;

    /** 失败验证次数 */
    @Excel(name = "失败验证次数")
    @NotNull(message = "失败验证次数不能为空")
    @Min(value = 0, message = "失败验证次数不能小于0")
    private Integer failedValidations;

    /** 通过率 */
    @Excel(name = "通过率")
    @DecimalMin(value = "0.0", message = "通过率不能小于0")
    @DecimalMax(value = "1.0", message = "通过率不能大于1")
    private Double passRate;

    /** 平均验证时间(毫秒) */
    @Excel(name = "平均验证时间")
    @Min(value = 0, message = "平均验证时间不能小于0")
    private Long avgValidationTime;

    /** 缓存命中率 */
    @Excel(name = "缓存命中率")
    @Min(value = 0, message = "缓存命中率不能小于0")
    @Max(value = 100, message = "缓存命中率不能大于100")
    private Integer cacheHitRate;

    /** 主要失败原因 */
    @Excel(name = "主要失败原因")
    @Size(max = 500, message = "主要失败原因长度不能超过500个字符")
    private String topFailureReason;

    /** 验证错误次数 */
    @Excel(name = "验证错误次数")
    @Min(value = 0, message = "验证错误次数不能小于0")
    private Integer errorValidations;

    /** 验证超时次数 */
    @Excel(name = "验证超时次数")
    @Min(value = 0, message = "验证超时次数不能小于0")
    private Integer timeoutValidations;

    /** 最大验证时间(毫秒) */
    @Excel(name = "最大验证时间")
    @Min(value = 0, message = "最大验证时间不能小于0")
    private Long maxValidationTime;

    /** 最小验证时间(毫秒) */
    @Excel(name = "最小验证时间")
    @Min(value = 0, message = "最小验证时间不能小于0")
    private Long minValidationTime;

    public void setStatisticsId(Long statisticsId) 
    {
        this.statisticsId = statisticsId;
    }

    public Long getStatisticsId() 
    {
        return statisticsId;
    }

    public void setStatisticsDate(Date statisticsDate) 
    {
        this.statisticsDate = statisticsDate;
    }

    public Date getStatisticsDate() 
    {
        return statisticsDate;
    }

    public void setTotalValidations(Integer totalValidations) 
    {
        this.totalValidations = totalValidations;
    }

    public Integer getTotalValidations() 
    {
        return totalValidations;
    }

    public void setPassedValidations(Integer passedValidations) 
    {
        this.passedValidations = passedValidations;
    }

    public Integer getPassedValidations() 
    {
        return passedValidations;
    }

    public void setFailedValidations(Integer failedValidations) 
    {
        this.failedValidations = failedValidations;
    }

    public Integer getFailedValidations() 
    {
        return failedValidations;
    }

    public void setPassRate(Double passRate) 
    {
        this.passRate = passRate;
    }

    public Double getPassRate() 
    {
        return passRate;
    }

    public void setAvgValidationTime(Long avgValidationTime) 
    {
        this.avgValidationTime = avgValidationTime;
    }

    public Long getAvgValidationTime() 
    {
        return avgValidationTime;
    }

    public void setCacheHitRate(Integer cacheHitRate) 
    {
        this.cacheHitRate = cacheHitRate;
    }

    public Integer getCacheHitRate() 
    {
        return cacheHitRate;
    }

    public void setTopFailureReason(String topFailureReason) 
    {
        this.topFailureReason = topFailureReason;
    }

    public String getTopFailureReason() 
    {
        return topFailureReason;
    }

    public void setErrorValidations(Integer errorValidations) 
    {
        this.errorValidations = errorValidations;
    }

    public Integer getErrorValidations() 
    {
        return errorValidations;
    }

    public void setTimeoutValidations(Integer timeoutValidations) 
    {
        this.timeoutValidations = timeoutValidations;
    }

    public Integer getTimeoutValidations() 
    {
        return timeoutValidations;
    }

    public void setMaxValidationTime(Long maxValidationTime) 
    {
        this.maxValidationTime = maxValidationTime;
    }

    public Long getMaxValidationTime() 
    {
        return maxValidationTime;
    }

    public void setMinValidationTime(Long minValidationTime) 
    {
        this.minValidationTime = minValidationTime;
    }

    public Long getMinValidationTime() 
    {
        return minValidationTime;
    }

    /**
     * 计算通过率
     */
    public void calculatePassRate() {
        if (totalValidations != null && totalValidations > 0 && passedValidations != null) {
            this.passRate = (double) passedValidations / totalValidations;
        } else {
            this.passRate = 0.0;
        }
    }

    /**
     * 检查是否有验证数据
     */
    public boolean hasValidationData() {
        return totalValidations != null && totalValidations > 0;
    }

    /**
     * 获取失败率
     */
    public Double getFailureRate() {
        if (passRate != null) {
            return 1.0 - passRate;
        }
        return null;
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
            .append("statisticsId", getStatisticsId())
            .append("statisticsDate", getStatisticsDate())
            .append("totalValidations", getTotalValidations())
            .append("passedValidations", getPassedValidations())
            .append("failedValidations", getFailedValidations())
            .append("passRate", getPassRate())
            .append("avgValidationTime", getAvgValidationTime())
            .append("cacheHitRate", getCacheHitRate())
            .append("topFailureReason", getTopFailureReason())
            .append("errorValidations", getErrorValidations())
            .append("timeoutValidations", getTimeoutValidations())
            .append("maxValidationTime", getMaxValidationTime())
            .append("minValidationTime", getMinValidationTime())
            .append("createTime", getCreateTime())
            .append("updateTime", getUpdateTime())
            .toString();
    }
}