package com.ruoyi.credit.service;

import java.util.Date;

/**
 * 验证规则引擎健康状态类
 * 记录引擎的健康检查结果
 * 
 * @author ruoyi
 * @date 2025-12-30
 */
public class EngineHealthStatus {
    
    /** 是否健康 */
    private boolean healthy;
    
    /** 激活规则数量 */
    private int activeRulesCount;
    
    /** 已注册验证器数量 */
    private int registeredValidatorsCount;
    
    /** 总体失败率 */
    private double overallFailureRate;
    
    /** 最后检查时间 */
    private Date lastCheckTime;
    
    /** 错误消息 */
    private String errorMessage;
    
    /** 检查详情 */
    private String details;
    
    /** 系统负载状态 */
    private String loadStatus = "NORMAL"; // NORMAL, HIGH, CRITICAL
    
    /** 内存使用率 */
    private Double memoryUsage;
    
    /** CPU使用率 */
    private Double cpuUsage;
    
    /**
     * 默认构造函数
     */
    public EngineHealthStatus() {
        this.healthy = true;
        this.lastCheckTime = new Date();
    }
    
    /**
     * 检查是否健康
     * 
     * @return 是否健康
     */
    public boolean isHealthy() {
        return healthy;
    }
    
    /**
     * 设置健康状态
     * 
     * @param healthy 是否健康
     */
    public void setHealthy(boolean healthy) {
        this.healthy = healthy;
    }
    
    /**
     * 获取激活规则数量
     * 
     * @return 激活规则数量
     */
    public int getActiveRulesCount() {
        return activeRulesCount;
    }
    
    /**
     * 设置激活规则数量
     * 
     * @param activeRulesCount 激活规则数量
     */
    public void setActiveRulesCount(int activeRulesCount) {
        this.activeRulesCount = activeRulesCount;
    }
    
    /**
     * 获取已注册验证器数量
     * 
     * @return 已注册验证器数量
     */
    public int getRegisteredValidatorsCount() {
        return registeredValidatorsCount;
    }
    
    /**
     * 设置已注册验证器数量
     * 
     * @param registeredValidatorsCount 已注册验证器数量
     */
    public void setRegisteredValidatorsCount(int registeredValidatorsCount) {
        this.registeredValidatorsCount = registeredValidatorsCount;
    }
    
    /**
     * 获取总体失败率
     * 
     * @return 总体失败率
     */
    public double getOverallFailureRate() {
        return overallFailureRate;
    }
    
    /**
     * 设置总体失败率
     * 
     * @param overallFailureRate 总体失败率
     */
    public void setOverallFailureRate(double overallFailureRate) {
        this.overallFailureRate = overallFailureRate;
    }
    
    /**
     * 获取最后检查时间
     * 
     * @return 最后检查时间
     */
    public Date getLastCheckTime() {
        return lastCheckTime;
    }
    
    /**
     * 设置最后检查时间
     * 
     * @param lastCheckTime 最后检查时间
     */
    public void setLastCheckTime(Date lastCheckTime) {
        this.lastCheckTime = lastCheckTime;
    }
    
    /**
     * 获取错误消息
     * 
     * @return 错误消息
     */
    public String getErrorMessage() {
        return errorMessage;
    }
    
    /**
     * 设置错误消息
     * 
     * @param errorMessage 错误消息
     */
    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }
    
    /**
     * 获取检查详情
     * 
     * @return 检查详情
     */
    public String getDetails() {
        return details;
    }
    
    /**
     * 设置检查详情
     * 
     * @param details 检查详情
     */
    public void setDetails(String details) {
        this.details = details;
    }
    
    /**
     * 获取系统负载状态
     * 
     * @return 系统负载状态
     */
    public String getLoadStatus() {
        return loadStatus;
    }
    
    /**
     * 设置系统负载状态
     * 
     * @param loadStatus 系统负载状态
     */
    public void setLoadStatus(String loadStatus) {
        this.loadStatus = loadStatus;
    }
    
    /**
     * 获取内存使用率
     * 
     * @return 内存使用率
     */
    public Double getMemoryUsage() {
        return memoryUsage;
    }
    
    /**
     * 设置内存使用率
     * 
     * @param memoryUsage 内存使用率
     */
    public void setMemoryUsage(Double memoryUsage) {
        this.memoryUsage = memoryUsage;
    }
    
    /**
     * 获取CPU使用率
     * 
     * @return CPU使用率
     */
    public Double getCpuUsage() {
        return cpuUsage;
    }
    
    /**
     * 设置CPU使用率
     * 
     * @param cpuUsage CPU使用率
     */
    public void setCpuUsage(Double cpuUsage) {
        this.cpuUsage = cpuUsage;
    }
    
    /**
     * 获取健康状态摘要
     * 
     * @return 健康状态摘要
     */
    public String getHealthSummary() {
        if (healthy) {
            return String.format("健康 - 激活规则: %d, 注册验证器: %d, 失败率: %.2f%%", 
                activeRulesCount, registeredValidatorsCount, overallFailureRate * 100);
        } else {
            return String.format("不健康 - %s", errorMessage != null ? errorMessage : "未知错误");
        }
    }
    
    @Override
    public String toString() {
        return "EngineHealthStatus{" +
                "healthy=" + healthy +
                ", activeRulesCount=" + activeRulesCount +
                ", registeredValidatorsCount=" + registeredValidatorsCount +
                ", overallFailureRate=" + String.format("%.4f", overallFailureRate) +
                ", lastCheckTime=" + lastCheckTime +
                ", errorMessage='" + errorMessage + '\'' +
                ", loadStatus='" + loadStatus + '\'' +
                ", memoryUsage=" + memoryUsage +
                ", cpuUsage=" + cpuUsage +
                '}';
    }
}