package cokr.xit.fims.chongno;

import java.util.List;

import javax.annotation.Resource;

import cokr.xit.fims.crdn.Crdn;
import cokr.xit.fims.crdn.CrdnQuery;
import cokr.xit.fims.levy.LevyQuery;
import cokr.xit.fims.levy.dao.LevyMapper;
import cokr.xit.fims.mngt.service.bean.TaskProcessor;
import cokr.xit.foundation.data.DataObject;

public class ChongnoTaskProcessor extends TaskProcessor {
	private static final String TASK_SE_CD = "RVS";

	public ChongnoTaskProcessor() {
		vltnCdGrps.set(TASK_SE_CD, "FIM090");
	}

	@Override
	public String[] getExtraCdGrps(String taskSeCd) {
		if (TASK_SE_CD.equals(taskSeCd))
			return new String[] {"FIM002"};
		return super.getExtraCdGrps(taskSeCd);
	}

	@Override
	public boolean isPreImposable(String taskSeCd) {
		return TASK_SE_CD.equals(taskSeCd)
			|| super.isPreImposable(taskSeCd);
	}

	@Resource(name = "levyMapper")
	private LevyMapper levyMapper;

	@Override
	public int[] getBasicAmt(Crdn crdn) {
		String taskSeCd = crdn.getTaskSeCd();
		if (TASK_SE_CD.equals(taskSeCd)) {
			String crdnYmd = crdn.getCrdnYmd();
			String sggCd = crdn.getSggCd();
			List<DataObject> levies = levyMapper.selectPrevLevyList(
				new LevyQuery()
				   .setSchVhrno(crdn.getVhrno())
				   .setSchVltnCd(crdn.getVltnCd())
				   .setRtpyrId(crdn.getRtpyrId())
				   .setDate(crdnYmd)
				   .setSggCd(sggCd)
				   .setTaskSeCd(taskSeCd)
			);
			String vcount = "0" + Math.min(levies.size() + 1, 3); // 위반횟수

			CrdnQuery query = new CrdnQuery()
				.setAplcnYmd(crdnYmd)
				.setAmtDcsnCdGroupId("FIM090")
				.setAmtDcsnCd("01")
				.setDtlAmtDcsnGroupId("FIM091")
				.setDtlAmtDcsnCd(vcount)
				.setTaskSeCd(taskSeCd)
				.setSggCd(sggCd);
			int amt = toInt(crdnStngMapper.selectBasicAmt(query));
			return new int[] {amt, amt};
		}
		return super.getBasicAmt(crdn);
	}

	@Override
	public String getSealCd3(String taskSeCd, String sndngSeCd) {
		if (TASK_SE_CD.equals(taskSeCd)) {

		}
		return super.getSealCd3(taskSeCd, sndngSeCd);
	}

	@Override
	public String getNtrisInterface(String taskSeCd) {
		return switch (taskSeCd) {
		case TASK_SE_CD -> "sntris";
		default -> super.getNtrisInterface(taskSeCd);
		};
	}
}