package cokr.xit.fims.cmmn.pdf.print.format;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import cokr.xit.applib.Print;
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 Advntce extends PDFPrintFormat {
	@Override
	public void initDefaultStng() {
		addForPost(
			image("postSenderLogo","우편물송신자로고","").a4(10, 0).letter(10, 0).size(0, 0),
			text("postSenderInst","우편물송신자기관","").a4(10, 5).letter(10, 5),
			text("postSenderDept","우편물송신자부서","").a4(50, 5).letter(50, 5),
			text("postSenderAddr","우편물송신자주소","").a4(10, 15).letter(10, 15),
			text("postSenderDtlAddr","우편물송신자상세주소","").a4(10, 25).letter(10, 25),
			text("postSenderZip","우편물송신자우편번호","").a4(10, 35).letter(10, 35),
			text("postSenderTel","우편물송신자전화번호","").a4(10, 45).letter(10, 45),
			text("postSenderFax","우편물송신자팩스번호","").a4(50, 45).letter(50, 45),

			text("postReceiverAddr","우편물수신자주소","").a4(100, 40).letter(100, 40).size(90, 0).align("right"),
			text("postReceiverDtlAddr","우편물수신자상세주소","").a4(100, 50).letter(100, 50).size(90, 0).align("right"),
			text("postReceiver","우편물수신자명","").a4(100, 60).letter(100, 60).size(90, 0).align("right"),
			text("postReceiverZip","우편물수신자우편번호","").a4(100, 70).letter(100, 70).size(90, 0).align("right")
		);

		add(
			image("background","배경이미지","").a4(0, 0).letter(0, 0).size(0, 0),
			images("crdnPhoto","단속사진","").a4(110, 100).letter(116, 95).size(90, 80),
			image("rprsCrdnPhoto","대표단속사진","").a4(10, 200).letter(10, 186).size(80, 80),

			text("rtpyrNm","수신자명",""),
			text("rtpyrNo","수신자번호",""),
			text("rtpyrAddr","수신자주소",""),
			text("rtpyrDtlAddr","수신자상세주소",""),
			text("rtpyrFullAddr","수신자전체주소",""),

			text("vhrno","차량번호",""),
			text("crdnYmd","단속일자",""),
			text("crdnYmdTm","단속일시",""),
			text("crdnPlc","단속장소",""),
			text("ffnlgCarmdlNm","차종",""),
			text("vltnArtcl","위반내용",""),
			text("vltnLawNm","위반법령",""),
			text("crdnSn","증거번호",""),
			text("ffnlgCrdnAmt","최초금액",""),

			text("advntceAmt","사전통지금액",""),
			text("advntceDudtYmd","납부기한",""),

			text("vrActno","대표가상계좌번호",""),
			text("vrActno1","가상계좌번호1",""),
			text("vrActno2","가상계좌번호2",""),
			text("vrActno3","가상계좌번호3",""),
			text("vrActno4","가상계좌번호4",""),
			text("vrActno5","가상계좌번호5",""),
			text("vrActno6","가상계좌번호6",""),
			text("vrActno7","가상계좌번호7",""),
			text("vrActno8","가상계좌번호8",""),
			text("vrActno9","가상계좌번호9",""),
			text("vrActno10","가상계좌번호10",""),
			text("epayNo","전자납부번호",""),

			text("otptYmd","출력일자","").offLog(),
			text("otptDt","출력일시","").offLog(),
			text("otptYYYY","출력년도","").offLog(),
			text("otptMM","출력월","").offLog(),
			text("otptDD","출력일","").offLog(),

			text("offcsText","관인명","").offLog(),
			image("offcs","관인이미지","").size(20, 20).offLog(),

			text("undefined","(미정)","미정항목").offLog()
		);
	}
	public Advntce() {
		super();
	}
	public Advntce(Print print, FimsPrintOption printOption,
			DataObject otptBscStng, List<DataObject> otptArtclStngList, String paperSeCd, List<DataObject> data){
		super(print,printOption,otptBscStng,otptArtclStngList,paperSeCd, data);
		this.print.setFormatKorName("사전통지서");
	}

	/**
	 * 출력요소에 매핑될 값을 반환한다.
	 */
	@Override
	public String getMappingValue(String otptArtclNm, String defaultValue, boolean forPost,
			DataObject dataObject, FimsPrintOption printOption, Print print) {

		String result = "";
		if(forPost) {
			return this.getValueForPost(otptArtclNm, defaultValue, dataObject, printOption, print);
		}

		Map<String, String> globalVariable = printOption.getGlobalVariable();

		switch(otptArtclNm) {
		case "background" -> {
			if(globalVariable.get("bcrnImgPath") != null) {
				result = globalVariable.get("bcrnImgPath");
			}
		}
		case "rprsCrdnPhoto" -> { //대표사진
			result = dataObject.string("CRDN_PHOTO1");
		}
		case "rprsCrdnPhotoKey" -> { //대표사진
			result = dataObject.string("CRDN_PHOTO1"+"KEY");
		}
		case "rtpyrNm" -> {
			result = dataObject.string("RTPYR_NM");
		}
		case "rtpyrNo" -> {
			result = dataObject.string("RTPYR_NO");
		}
		case "rtpyrAddr" -> {
			result = dataObject.string("RTPYR_ADDR");
		}
		case "rtpyrDtlAddr" -> {
			result = dataObject.string("RTPYR_DTL_ADDR");
		}
		case "rtpyrFullAddr" -> {
			result = dataObject.string("RTPYR_FULL_ADDR");
		}
		case "rtpyrZip" -> {
			result = dataObject.string("RTPYR_ZIP");
		}
		case "vhrno" -> {
			result = dataObject.string("VHRNO");
		}
		case "crdnYmd" -> {
			result = DataFormat.yyyy_mm_dd(dataObject.string("CRDN_YMD"));
		}
		case "crdnYmdTm" -> {
			result = DataFormat.yyyy_mm_dd_hh_mm_ss(dataObject.string("CRDN_YMD_TM"));
		}
		case "crdnPlc" -> {
			result = dataObject.string("CRDN_PLC");
		}
		case "ffnlgCarmdlNm" -> {
			result = dataObject.string("FFNLG_CARMDL_NM");
		}
		case "vltnArtcl" -> {
			result = dataObject.string("VLTN_ARTCL");
		}
		case "vltnLawNm" -> {
			result = dataObject.string("VLTN_LAW_NM");
		}
		case "crdnSn" -> {
			result = dataObject.string("CRDN_SN");
		}
		case "ffnlgCrdnAmt" -> {
			result = dataObject.string("FFNLG_CRDN_AMT");
		}
		case "advntceAmt" -> {
			result = DataFormat.n_nn0(dataObject.string("ADVNTCE_AMT"));
		}
		case "advntceDudtYmd" -> {
			result = DataFormat.yyyy_mm_dd(dataObject.string("ADVNTCE_DUDT_YMD"));
		}

		case "vrActno" -> {
			result = dataObject.string("VR_ACTNO");
		}
		case "vrActno1" -> {
			result = dataObject.string("VR_ACTNO1");
		}
		case "vrActno2" -> {
			result = dataObject.string("VR_ACTNO2");
		}
		case "vrActno3" -> {
			result = dataObject.string("VR_ACTNO3");
		}
		case "vrActno4" -> {
			result = dataObject.string("VR_ACTNO4");
		}
		case "vrActno5" -> {
			result = dataObject.string("VR_ACTNO5");
		}
		case "vrActno6" -> {
			result = dataObject.string("VR_ACTNO6");
		}
		case "vrActno7" -> {
			result = dataObject.string("VR_ACTNO7");
		}
		case "vrActno8" -> {
			result = dataObject.string("VR_ACTNO8");
		}
		case "vrActno9" -> {
			result = dataObject.string("VR_ACTNO9");
		}
		case "vrActno10" -> {
			result = dataObject.string("VR_ACTNO10");
		}
		case "epayNo" -> {
			result = dataObject.string("EPAY_NO");
		}

		case "otptYmd" -> {
			result = DataFormat.yyyy_mm_dd(print.getPrintRequestDt().substring(0,8));
		}
		case "otptDt" -> {
			result = DataFormat.yyyy_mm_dd_hh_mm_ss(print.getPrintRequestDt());
		}
		case "otptYYYY" -> {
			result = print.getPrintRequestDt().substring(0,4);
		}
		case "otptMM" -> {
			result = print.getPrintRequestDt().substring(4,6);
		}
		case "otptDD" -> {
			result = print.getPrintRequestDt().substring(6,8);
		}

		case "offcsText" -> {
			String instNm = (String) print.getPrintRequestUserInfo().getInfo().get("instNm");
			instNm = OgdpUtil.getLastWord(instNm);
			instNm = OgdpUtil.getInstituteLeader(instNm, true);
			result = instNm;
		}
		case "offcs" -> {
			result = globalVariable.get("offcsFilePath");
		}

		case "undefined" -> {
			result = defaultValue;
		}
		}

		return result;
	}

	/**
	 * 우편물 출력요소에 매핑될 값을 반환한다.
	 */
	@Override
	public String getValueForPost(String otptArtclNm, String defaultValue,
			DataObject dataObject, FimsPrintOption printOption, Print print) {
		String result = "";

		switch(otptArtclNm) {
		case "postReceiverAddr" -> {
			result = dataObject.string("RTPYR_ADDR");
		}
		case "postReceiverDtlAddr" -> {
			result = dataObject.string("RTPYR_DTL_ADDR");
		}
		case "postReceiverZip" -> {
			result = dataObject.string("RTPYR_ZIP");
		}
		case "postReceiver" -> {
			result = dataObject.string("RTPYR_NM");
		}
		case "postSenderLogo" -> {
			result = printOption.getGlobalVariable().get("logoFilePath");
		}
		case "postSenderInst" -> {
			result = (String)print.getPrintRequestUserInfo().getInfo().get("instNm");
		}
		case "postSenderDept" -> {
			result = (String)print.getPrintRequestUserInfo().getInfo().get("deptNm");
		}
		case "postSenderAddr" -> {
			result = printOption.getGlobalVariable().get("instAddr");
		}
		case "postSenderDtlAddr" -> {
			result = printOption.getGlobalVariable().get("instDaddr");
		}
		case "postSenderZip" -> {
			result = printOption.getGlobalVariable().get("instZip");
		}
		case "postSenderTel" -> {
			result = printOption.getGlobalVariable().get("deptTelno");
		}
		case "postSenderFax" -> {
			result = printOption.getGlobalVariable().get("deptFxno");
		}

		}
		return result;
	}


	@Override
	public List<String> getMappingValues(String otptArtclNm, String defaultValue, boolean forPost,
			DataObject dataObject, FimsPrintOption printOption, Print print) {
		List<String> result = new ArrayList<String>();

		switch(otptArtclNm) {
			case "crdnPhoto" -> {
				int i = 1;
				while(!dataObject.string("CRDN_PHOTO"+i).isEmpty()) {
					result.add(dataObject.string("CRDN_PHOTO"+i));
					i++;
				}
			}
			case "crdnPhotoKey" -> {
				int i = 1;
				while(!dataObject.string("CRDN_PHOTO"+i+"KEY").isEmpty()) {
					result.add(dataObject.string("CRDN_PHOTO"+i+"KEY"));
					i++;
				}
			}
		}

		return result;
	}


	/**
	 * 출력용 샘플 데이터를 생성한다.
	 */
	@Override
	public DataObject createSampleData() {
		DataObject dataObject = new DataObject();
		dataObject.put("RTPYR_NM", "홍길동");
		dataObject.put("RTPYR_ADDR", "무슨도 무슨시 무슨구");
		dataObject.put("RTPYR_DTL_ADDR", "ㅇㅇ아파트 999호");
		dataObject.put("RTPYR_FULL_ADDR", "무슨도 무슨시 무슨구 ㅇㅇ아파트 999호");
		dataObject.put("RTPYR_ZIP", "12345");
		dataObject.put("VHRNO", "00가0000");
		dataObject.put("CRDN_YMD", "20231204");
		dataObject.put("CRDN_YMD_TM", "20231204080808");
		dataObject.put("CRDN_PLC", "사거리 건너편");
		dataObject.put("FFNLG_CARMDL_NM", "승용");
		dataObject.put("VLTN_ARTCL", "주차위반");
		dataObject.put("VLTN_LAW_NM", "00법 제0조 제0항");
		dataObject.put("CRDN_SN", "1234567890");
		dataObject.put("VR_ACTNO", "000000-00-000000");
		dataObject.put("VR_ACTNO1", "111111-00-000000");
		dataObject.put("VR_ACTNO2", "222222-00-000000");
		dataObject.put("VR_ACTNO3", "333333-00-000000");
		dataObject.put("VR_ACTNO4", "444444-00-000000");
		dataObject.put("VR_ACTNO5", "555555-00-000000");
		dataObject.put("VR_ACTNO6", "666666-00-000000");
		dataObject.put("VR_ACTNO7", "777777-00-000000");
		dataObject.put("VR_ACTNO8", "888888-00-000000");
		dataObject.put("VR_ACTNO9", "999999-00-000000");
		dataObject.put("VR_ACTNO10", "101010-00-000000");
		dataObject.put("EPAY_NO", "00000-0-00-00-000000000");
		dataObject.put("FFNLG_CRDN_AMT", "100000");
		dataObject.put("ADVNTCE_AMT", "80000");
		dataObject.put("ADVNTCE_DUDT_YMD", "20231231");

		dataObject.put("CRDN_PHOTO1", "samplefiles/crdn1.png");
		dataObject.put("CRDN_PHOTO2", "samplefiles/crdn2.png");
		dataObject.put("CRDN_PHOTO3", "samplefiles/crdn3.png");
		dataObject.put("CRDN_PHOTO4", "samplefiles/crdn4.png");
		dataObject.put("CRDN_PHOTO5", "samplefiles/crdn5.png");
		dataObject.put("CRDN_PHOTO6", "samplefiles/crdn6.png");
		dataObject.put("CRDN_PHOTO7", "samplefiles/crdn7.png");

		return dataObject;
	}
}
