package cokr.xit.fims.nxrp;

import org.egovframe.rte.fdl.string.EgovStringUtil;

import cokr.xit.applib.Hangul;
import cokr.xit.fims.cmmn.UnnamedItems;

public class C01 extends UnnamedItems {

	class HasText {
		public static final int[] maxByteLen = {14,30,2,10,2,60,60,1,10,20,20,10,10,3};
		public static final String[] defaultValue = {"","","","","","","","1","0000000000","","","","",""};
	}
	class NoText {
		public static final int[] maxByteLen = {17,30,2,10,2,60,1,10,20,20,1,4};
		public static final String[] defaultValue = {"","","","","","","1","0000000000","000","000","",""};
	}

	protected Hangul hangul;
	protected boolean includeTxt;

	public C01(boolean includeTxt){
		this.hangul = new Hangul(3);
		this.includeTxt = includeTxt;

		int itemCount = 0;
		if(includeTxt) {
			itemCount = 14;
		} else {
			String[] unused = {"파일순서", "확장자"};
			itemCount = 12 - unused.length;
		}

		items = new String[itemCount];
	}

	@Override
	public void set(int i, String str) {
		if(this.includeTxt) {
			if(HasText.maxByteLen[i-1] != 0 && hangul.getByteLength(str) > HasText.maxByteLen[i-1]) {
				throw new RuntimeException("[F]"+i+"번째 항목 "+HasText.maxByteLen[i-1]+"바이트 초과 오류");
			}

			if(EgovStringUtil.null2void(str).equals("")) {
				super.set(i, HasText.defaultValue[i-1]);
			} else {
				super.set(i, str);
			}

		} else {
			if(NoText.maxByteLen[i-1] != 0 && hangul.getByteLength(str) > NoText.maxByteLen[i-1]) {
				throw new RuntimeException("[F]"+i+"번째 항목 "+NoText.maxByteLen[i-1]+"바이트 초과 오류");
			}

			if(EgovStringUtil.null2void(str).equals("")) {
				super.set(i, NoText.defaultValue[i-1]);
			} else {
				super.set(i, str);
			}

		}
	}
}
