package com.brilliance.isc.common.transaction.newcheck.liaall;

import com.brilliance.isc.common.liaall.service.LiaallService;
import com.brilliance.isc.common.liaall.vo.AcceptLineVo;
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 com.brilliance.mda.runtime.mda.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
public class AcceptLineValidator extends AbstractModuleValidator<AcceptLineVo> {

    @Autowired
    private LiaallService liaallService;

    @Override
    @PostConstruct
    public void register() {
        super.register();
    }

    @Validate(path="liaall.acceptLines.%s.matdat")
    public ValidResult checkMatdatN1000(AcceptLineVo acceptLine){
        if(!liaallService.liaallCBTPFXIsBalance(acceptLine.getCbtpfx()) && Strings.isEmpty(acceptLine.getMatdat()) && (Strings.notEmpty(acceptLine.getAmt()) || Strings.notEmpty(acceptLine.getOldamt()))){
            return errorMandatory();
        }
        return null;
    }
}
