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