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 AmountConsistencyValidator implements RuleValidator {
    
    private static final Logger log = LoggerFactory.getLogger(AmountConsistencyValidator.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(), "amount_consistency");
        }
    }
    
    @Override
    public String getValidatorName() {
        return "金额一致性验证器";
    }
    
    @Override
    public String getSupportedRuleType() {
        return ValidationRule.TYPE_AMOUNT_CONSISTENCY;
    }
}