package cokr.xit.fims.cmmn.xls;

import java.io.File;
import java.util.Map;

import org.apache.poi.hssf.util.HSSFColor;

import cokr.xit.base.docs.xls.Comment;
import cokr.xit.base.docs.xls.Format;
import cokr.xit.base.docs.xls.Style;
import cokr.xit.foundation.data.DataFormat;

public class FormatMaker {

	@SuppressWarnings("rawtypes")
	public static Format photoCellForApproval(Format format, Comment comment, String key) {
		return format.of(key)
			.value(obj -> {
				if(((Map)obj).get(key) == null) {
					return "없음";
				}
				String value = (String)((Map)obj).get(key);
				if(value.equals("")) {
					return "없음";
				}
				if(!(new File(value)).exists()) {
					return "이미지 경로 존재하지 않음";
				}
				if((new File(value)).length() == 0) {
					return "이미지 크기 오류";
				}
				if((new File(value)).length() > (1024 * 1024 * 3)){
					return "사진크기(3MB)초과";
				}
				return " ";
			})
			.onCell(obj -> {
				if(((Map)obj).get(key) == null) { return; }
				String value = (String)((Map)obj).get(key);
				if(value.equals("")) { return; }
				if(!(new File(value)).exists()) { return; }
				if((new File(value)).length() == 0) { return; }
				if((new File(value)).length() > (1024 * 1024 * 3)){ return; }

				comment.setImageComment((String)((Map)obj).get(key));
			})
			.style(new Style().foregroundColor(HSSFColor.HSSFColorPredefined.YELLOW.getIndex()));
	}


	@SuppressWarnings("rawtypes")
	public static Format yyyy_mm_dd_hh_mm_ss(Format format, String key) {
		return format.of(key).value(o -> {
			return DataFormat.yyyy_mm_dd_hh_mm_ss(((Map) o).get(key));
		});
	}


	@SuppressWarnings("rawtypes")
	public static Format yyyy_mm_dd(Format format, String key) {
		return format.of(key).value(o -> {
			return DataFormat.yyyy_mm_dd(((Map) o).get(key));
		});
	}



}
