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

import com.brilliance.isc.common.rmbbop.model.Tdngrp;
import com.brilliance.isc.common.rmbbop.vo.Rmb2106;
import com.brilliance.isc.common.transaction.newcheck.AbstractModuleValidator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.Map;

@Component
public class Rmb2106Validator extends AbstractModuleValidator<Rmb2106> {
    @Autowired
    private TejValidator tejValidator;
    @Autowired
    private TekValidator tekValidator;

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

    @Override
    public Map<String, String> validate(Rmb2106 rmb2106) {
        Map<String, String> maps = super.validate(rmb2106);
        Tdngrp recgrp = rmb2106.getRecgrp();
        tejValidator.registerParent(rmb2106);
        for (int i = 0; i < recgrp.getTej().size(); i++) {
            maps.putAll(tejValidator.validate(recgrp.getTej().get(i), i));
        }
        tejValidator.removeTl();
        tekValidator.registerParent(rmb2106);
        for (int i = 0; i < recgrp.getTek().size(); i++) {
            maps.putAll(tekValidator.validate(recgrp.getTek().get(i), i));
        }
        tekValidator.removeTl();
        return maps;
    }
}
