package cokr.xit.fims.cmmn.hwp.format;

import java.util.List;

import cokr.xit.applib.Print;
import cokr.xit.applib.hwp.format.HWPFormat;
import cokr.xit.fims.cmmn.FimsPrintOption;
import cokr.xit.fims.mngt.OgdpUtil;
import cokr.xit.foundation.data.DataFormat;
import cokr.xit.foundation.data.DataObject;

/**
 * 단속확인서
 */
public class CrdnConfirm extends HWPFormat {

	public CrdnConfirm(Print print, FimsPrintOption printOption, List<DataObject> dataObjectList) {
		super(print, printOption, dataObjectList);
		this.maxRunCount = dataObjectList.size();
		this.formatFilePath = "template/hwp/crdnConfirm.hwp";
		this.print.setFormatKorName("단속확인서");
		this.print.setFormatName("crdnConfirm");
	}

	@Override
	public List<String> getDownloadDataNames() {
		return List.of("과태료구분","차량번호","단속일시","위반내용","단속장소","단속동","단속조","소유자명","소유자주소");
	}



	@Override
	public void runAsWriter() {


		String printRequestYmd = print.getPrintRequestDt().substring(0, 8);
		String yyyy = printRequestYmd.substring(0, 4);
		String mm = printRequestYmd.substring(4, 6);
		String dd = printRequestYmd.substring(6, 8);
		String ymd = yyyy+"년 "+mm+"월 "+dd+"일";

		String instNm = OgdpUtil.getInstituteLeader((String)print.getPrintRequestUserInfo().getInfo().get("instNm"), false);


		DataObject one = data.get(currentRunCount);
		DataObject newObj = (DataObject) new DataObject()
		.set("과태료", one.string("TASK_SE_NM"))
		.set("차량번호", one.string("VHRNO"))
		.set("단속일시", DataFormat.yyyy_mm_dd_hh_mm_ss(one.string("CRDN_YMD_TM")))
		.set("위반내용", one.string("VLTN_ARTCL"))
		.set("단속장소", one.string("CRDN_PLC"))
		.set("단속동", one.string("CRDN_STDG_NM"))
		.set("단속조", one.string("TEAM_NM"))
		.set("소유자", one.string("RTPYR_NM"))
		.set("주소", one.string("RTPYR_FULL_ADDR"))
		.set("우편번호", one.string("RTPYR_ZIP"))
		.set("연월일", ymd)
		.set("발신", instNm);

		if(!one.string("PHOTO1").isEmpty()) {
			newObj.set("왼쪽위사진", writer.image().add(one.string("PHOTO1")));
		}
		if(!one.string("PHOTO2").isEmpty()) {
			newObj.set("오른쪽위사진", writer.image().add(one.string("PHOTO2")));
		}
		if(!one.string("PHOTO3").isEmpty()) {
			newObj.set("왼쪽아래사진", writer.image().add(one.string("PHOTO3")));
		}
		if(!one.string("PHOTO4").isEmpty()) {
			newObj.set("오른쪽아래사진", writer.image().add(one.string("PHOTO4")));
		}

		writer.table(0, 0, 13).setValues(List.of(newObj));

	}



}
