package com.ruoyi.credit.domain;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import javax.validation.constraints.Min;

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

import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;

/**
 * 验证规则配置对象 dc_validation_rule
 * 
 * @author ruoyi
 * @date 2025-12-30
 */
public class ValidationRule extends BaseEntity
{
    private static final long serialVersionUID = 1L;

    /** 规则ID */
    private Long ruleId;

    /** 规则名称 */
    @Excel(name = "规则名称")
    @NotBlank(message = "规则名称不能为空")
    @Size(max = 100, message = "规则名称长度不能超过100个字符")
    private String ruleName;

    /** 规则类型 */
    @Excel(name = "规则类型")
    @NotBlank(message = "规则类型不能为空")
    @Size(max = 50, message = "规则类型长度不能超过50个字符")
    private String ruleType;

    /** 规则表达式 */
    @Excel(name = "规则表达式")
    @NotBlank(message = "规则表达式不能为空")
    @Size(max = 2000, message = "规则表达式长度不能超过2000个字符")
    private String ruleExpression;

    /** 优先级 */
    @Excel(name = "优先级")
    @NotNull(message = "优先级不能为空")
    @Min(value = 1, message = "优先级必须大于0")
    private Integer priority;

    /** 规则状态 */
    @Excel(name = "规则状态")
    @NotBlank(message = "规则状态不能为空")
    @Size(max = 20, message = "规则状态长度不能超过20个字符")
    private String ruleStatus;

    /** 规则描述 */
    @Excel(name = "规则描述")
    @Size(max = 1000, message = "规则描述长度不能超过1000个字符")
    private String description;

    /** 规则配置JSON */
    @Excel(name = "规则配置")
    @Size(max = 4000, message = "规则配置长度不能超过4000个字符")
    private String configJson;

    /** 创建人 */
    @Excel(name = "创建人")
    @Size(max = 100, message = "创建人长度不能超过100个字符")
    private String createdBy;

    // 规则状态常量
    public static final String STATUS_ACTIVE = "ACTIVE";       // 激活状态
    public static final String STATUS_INACTIVE = "INACTIVE";   // 非激活状态
    public static final String STATUS_DRAFT = "DRAFT";         // 草稿状态
    public static final String STATUS_DEPRECATED = "DEPRECATED"; // 已废弃

    // 规则类型常量
    public static final String TYPE_CREDIT_EXISTENCE = "CREDIT_EXISTENCE";     // 债权凭证存在性验证
    public static final String TYPE_CREDIT_VALIDITY = "CREDIT_VALIDITY";       // 债权凭证有效性验证
    public static final String TYPE_CONTRACT_MATCH = "CONTRACT_MATCH";         // 合同匹配验证
    public static final String TYPE_AMOUNT_CONSISTENCY = "AMOUNT_CONSISTENCY"; // 金额一致性验证
    public static final String TYPE_DATE_CONSISTENCY = "DATE_CONSISTENCY";     // 日期一致性验证
    public static final String TYPE_STATUS_VALIDATION = "STATUS_VALIDATION";   // 状态验证


    public void setRuleId(Long ruleId) 
    {
        this.ruleId = ruleId;
    }

    public Long getRuleId() 
    {
        return ruleId;
    }

    public void setRuleName(String ruleName) 
    {
        this.ruleName = ruleName;
    }

    public String getRuleName() 
    {
        return ruleName;
    }

    public void setRuleType(String ruleType) 
    {
        this.ruleType = ruleType;
    }

    public String getRuleType() 
    {
        return ruleType;
    }

    public void setRuleExpression(String ruleExpression) 
    {
        this.ruleExpression = ruleExpression;
    }

    public String getRuleExpression() 
    {
        return ruleExpression;
    }

    public void setPriority(Integer priority) 
    {
        this.priority = priority;
    }

    public Integer getPriority() 
    {
        return priority;
    }

    public void setRuleStatus(String ruleStatus) 
    {
        this.ruleStatus = ruleStatus;
    }

    public String getRuleStatus() 
    {
        return ruleStatus;
    }

    public void setDescription(String description) 
    {
        this.description = description;
    }

    public String getDescription() 
    {
        return description;
    }

    public void setConfigJson(String configJson) 
    {
        this.configJson = configJson;
    }

    public String getConfigJson() 
    {
        return configJson;
    }

    public void setCreatedBy(String createdBy) 
    {
        this.createdBy = createdBy;
    }

    public String getCreatedBy() 
    {
        return createdBy;
    }

    /**
     * 检查规则是否激活
     */
    public boolean isActive() {
        return STATUS_ACTIVE.equals(this.ruleStatus);
    }

    /**
     * 检查规则是否为草稿状态
     */
    public boolean isDraft() {
        return STATUS_DRAFT.equals(this.ruleStatus);
    }

    /**
     * 检查规则是否已废弃
     */
    public boolean isDeprecated() {
        return STATUS_DEPRECATED.equals(this.ruleStatus);
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
            .append("ruleId", getRuleId())
            .append("ruleName", getRuleName())
            .append("ruleType", getRuleType())
            .append("ruleExpression", getRuleExpression())
            .append("priority", getPriority())
            .append("ruleStatus", getRuleStatus())
            .append("description", getDescription())
            .append("configJson", getConfigJson())
            .append("createdBy", getCreatedBy())
            .append("createTime", getCreateTime())
            .append("updateTime", getUpdateTime())
            .toString();
    }
}