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

import com.brilliance.isc.bo.Ear;
import com.brilliance.isc.bo.model.Cfaeaf;
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 CfaEafearValidator extends AbstractModuleValidator<Ear> {

    @Autowired(required = false)
    EblmodService eblmodService;

    @Autowired(required = false)
    CfaearpCheckRules cfaearpCheckRules;

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

    @Validate(path = "cfabop.cfaeaf.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.cfaeaf.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.cfaeaf.recgrp.dcl.%s.chamount")
    public ValidResult checkChamountN1000(Ear ear){
        if(!eblmodService.isCheckField("X",ear.getActiontype())){
            return null;
        }
        Cfaeaf cfaeaf = (Cfaeaf) getParent();
        return cfaearpCheckRules.checkChamountN1000(ear.getChamount(),cfaeaf.getRecgrp().getBas().getContractamount(),ear.getChangtype());
    }

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

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

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


}
