package com.ruoyi.credit.service.validator;

import com.ruoyi.credit.domain.ValidationRule;
import com.ruoyi.credit.service.RuleConfig;
import com.ruoyi.credit.service.RuleValidator;
import com.ruoyi.credit.service.ValidationContext;
import com.ruoyi.credit.service.ValidationResult;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * 状态验证器
 * 验证相关实体的状态是否符合要求
 * 
 * @author ruoyi
 * @date 2025-01-05
 */
@Component
public class StatusValidationValidator implements RuleValidator {
    
    private static final Logger log = LoggerFactory.getLogger(StatusValidationValidator.class);
    
    @Override
    public ValidationResult validate(ValidationRule rule, RuleConfig config, ValidationContext context) {
        log.debug("开始执行状态验证，贷款ID: {}", context.getLoanId());
        
        try {
            // 这里可以添加状态验证逻辑
            // 比如验证贷款状态、债权凭证状态、服务周期状态等
            
            // 目前简化实现：直接通过验证
            log.debug("状态验证通过，贷款ID: {}", context.getLoanId());
            return ValidationResult.success("状态验证通过");
            
        } catch (Exception e) {
            log.error("状态验证异常，贷款ID: {}", context.getLoanId(), e);
            return ValidationResult.error("状态验证异常: " + e.getMessage(), "status_validation");
        }
    }
    
    @Override
    public String getValidatorName() {
        return "状态验证器";
    }
    
    @Override
    public String getSupportedRuleType() {
        return ValidationRule.TYPE_STATUS_VALIDATION;
    }
}