package com.brilliance.isc.common.transaction.newcheck.bopset.cfacheck;

import com.brilliance.isc.bo.Ear;
import com.brilliance.isc.bo.model.Cfaead;
import com.brilliance.isc.common.bopset.service.EblmodService;
import com.brilliance.isc.common.transaction.newcheck.AbstractModuleValidator;
import com.brilliance.isc.common.transaction.newcheck.ValidResult;
import com.brilliance.isc.common.transaction.newcheck.Validate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


@Component
public class CfaEadearValidator extends AbstractModuleValidator<Ear> {

    @Autowired(required = false)
    EblmodService eblmodService;

    @Autowired(required = false)
    CfaearpCheckRules cfaearpCheckRules;

    @Validate(path = "cfabop.cfaead.recgrp.dcl.%s.actiondesc")
    public ValidResult checkActiondescN1000(Ear ear) {
        return cfaearpCheckRules.checkActiondescN1000(ear.getActiondesc(),ear.getActiontype());
    }

    @Validate(path = "cfabop.cfaead.recgrp.dcl.%s.actiontype")
    public ValidResult checkActiontypeN1000(Ear ear) {
        if(!eblmodService.isCheckField("X",ear.getActiontype())){
            return null;
        }

        return cfaearpCheckRules.checkActiontypeN1000(ear.getActiontype());
    }

    @Validate(path = "cfabop.cfaead.recgrp.dcl.%s.buscode")
    public ValidResult checkBuscodeN1000(Ear ear){
        if(!eblmodService.isCheckField("X",ear.getActiontype())){
            return null;
        }
        return cfaearpCheckRules.checkBuscodeN1000(ear.getBuscode());
    }

    @Validate(path = "cfabop.cfaead.recgrp.dcl.%s.chamount")
    public ValidResult checkChamountN1000(Ear ear){
        if(!eblmodService.isCheckField("X",ear.getActiontype())){
            return null;
        }
        Cfaead cfaead = (Cfaead) getParent();
        return cfaearpCheckRules.checkChamountN1000(ear.getChamount(),cfaead.getRecgrp().getBas().getContractamount(),ear.getChangtype());
    }

    @Validate(path = "cfabop.cfaead.recgrp.dcl.%s.changtype")
    public ValidResult checkChangtypeN1000(Ear ear){
        if(!eblmodService.isCheckField("X",ear.getActiontype())){
            return null;
        }
        Cfaead cfaead = (Cfaead) getParent();
        return cfaearpCheckRules.checkChangtypeN1000(ear.getChangtype(),ear.getChangeno(),cfaead.getRecgrp().getBas().getInr());
    }

    @Validate(path = "cfabop.cfaead.recgrp.dcl.%s.chcurrency")
    public ValidResult checkChcurrencyN1000(Ear ear){
        if(!eblmodService.isCheckField("X",ear.getActiontype())){
            return null;
        }
        Cfaead cfaead = (Cfaead) getParent();
        return cfaearpCheckRules.checkChcurrencyN1000(ear.getChcurrency(),cfaead.getRecgrp().getBas().getContractcurr());
    }

    @Validate(path = "cfabop.cfaead.recgrp.dcl.%s.chdate")
    public ValidResult checkChdateN1000(Ear ear){
        if(!eblmodService.isCheckField("X",ear.getActiontype())){
            return null;
        }
        Cfaead cfaead = (Cfaead) getParent();
        return cfaearpCheckRules.checkChdateN1000(ear.getChdate(),cfaead.getRecgrp().getBas().getValuedate());
    }




}
