package com.simuwang.base.pojo.valuation;
import java.util.HashMap;
import java.util.Map;

public class ImportParams {
	private static final String HEADER_IDENTIFY_V1 = "科目代码";
	private static final String[] HEADER_IDENTIFY_V2 = ValuationTableConfig.SUBJECT_CODE.split(",");

	private static final String Footer_IDENTIFY_V1 = "制表";

	/** header所占行数 */
	private int headerRows = 0;

	/** 列标题所占行数 */
	private int titleRows = 1;

	/** footer所占行数 */
	private int footerRows = 0;

	/** 优先级高于行数 */
	private String headerIdentify = null;
	/** 优先级高于行数 */
	private String footerIdentify = null;

	private static final Map<AssetsValuationType, Class<? extends PreAssetsValuationBase>> typeClassMap = new HashMap<>();
	static {
		typeClassMap.put(AssetsValuationType.GeneralTemplate, PreAssetsValuationGeneralTemplate.class);

	}

	public static boolean isEqualHeaderIdentify(String str) {
		if (HEADER_IDENTIFY_V1.equals(str)) {
			return true;
		}

		for (String identify : HEADER_IDENTIFY_V2) {
			if (identify.equals(str)) {
				return true;
			}
		}

		return false;
	}

	public static boolean isContainFooterIdentify(String str) {
		return (null != str && str.contains(Footer_IDENTIFY_V1));
	}

	public static Class<? extends PreAssetsValuationBase> getPreprocessEntity(AssetsValuationType type) {
		if (null == type) {
			return null;
		}

		return typeClassMap.entrySet().stream().filter(e -> e.getKey().getId() == type.getId()).findFirst().get()
				.getValue();
	}

	/** 提供默认模板配置 */
	public static ImportParams getDefaultImportParams(AssetsValuationType type) {
		switch (type) {
			case YSSTech :
				return getYYSTech();
			case HangSeng :
				return getHangSeng();
			case SZKingdom :
				return getSZKingdom();
			case BaiHang :
				return getBaiHang();
			default :
				return getGeneralTemplate();
		}
	}

	private static ImportParams getGeneralTemplate() {
		ImportParams params = new ImportParams();
		params.setHeaderIdentify(HEADER_IDENTIFY_V1);
		params.setTitleRows(1);
		return params;
	}

	/** 百航BaiHang-默认模板配置 */
	private static ImportParams getBaiHang() {
		ImportParams params = new ImportParams();
		params.setHeaderIdentify(HEADER_IDENTIFY_V1);
		params.setTitleRows(1);
		return params;
	}

	/** 赢时胜YYSTech-默认模板配置 */
	public static ImportParams getYYSTech() {
		ImportParams params = new ImportParams();
		params.setHeaderIdentify(HEADER_IDENTIFY_V1);
		params.setTitleRows(2);
		return params;
	}

	/** 恒生HangSeng-默认模板配置 */
	public static ImportParams getHangSeng() {
		ImportParams params = new ImportParams();
		params.setHeaderIdentify(HEADER_IDENTIFY_V1);
		params.setFooterIdentify(Footer_IDENTIFY_V1);
		params.setTitleRows(1);
		return params;
	}

	/** 金证SZKingdom-默认模板配置 */
	public static ImportParams getSZKingdom() {
		ImportParams params = new ImportParams();
		params.setHeaderIdentify(HEADER_IDENTIFY_V1);
		params.setTitleRows(2);
		return params;
	}

	public String getHeaderIdentify() {
		return headerIdentify;
	}

	public void setHeaderIdentify(String headerIdentify) {
		this.headerIdentify = headerIdentify;
	}

	public String getFooterIdentify() {
		return footerIdentify;
	}

	public void setFooterIdentify(String footerIdentify) {
		this.footerIdentify = footerIdentify;
	}

	public int getTitleRows() {
		return titleRows;
	}

	public void setTitleRows(int titleRows) {
		this.titleRows = titleRows;
	}

	public int getHeaderRows() {
		return headerRows;
	}

	public void setHeaderRows(int headerRows) {
		this.headerRows = headerRows;
	}

	public int getFooterRows() {
		return footerRows;
	}

	public void setFooterRows(int footerRows) {
		this.footerRows = footerRows;
	}
}
