import BusinessTypeSetting from "../../_BusinessTypeSetting/BusinessTypeSetting";
import CSSettingsSDV3 from "../../FormTable/CSSettingsV3";
import { LanguageManager } from "../Manage/Language/LanguageManager";

declare module "../../FormTable/CSSettingsV3" {
	export default interface CSSettingsV3 {
		/**
		 * 共用String表欄位值
		 * @param formId
		 */
		CommonString(formId: number): string;
		/**
		 * 排行榜String表欄位值
		 * @param formId
		 */
		RankString(formId: number): string;
		/**
		 * VipString表欄位值
		 * @param formId
		 */
		VipString(formId: number): string;
		/**
		 * PacketString表欄位值
		 * @param formId
		 */
		PacketString(formId: number): string;
		/**
		 * MissionString表欄位值
		 * @param formId
		 */
		TaskString(formId: number): string;
		/**
		 * ChatString表欄位值
		 * @param formId
		 */
		ChatString(formId: number): string;
		/**
		 * CommunityString表欄位值
		 * @param formId
		 */
		CommunityString(formId: number): string;
		/**
		 * 贈禮String表欄位值
		 * @param formId
		 */
		GiftString(formId: number): string;
		/**
		 * 大廳String表欄位值
		 * @param slotID
		 */
		LobbyString(formId: number): string;
		/**
		 * 兌禮String表欄位值
		 * @param slotID
		 */
		LpPointString(formId: number): string;
		/**
		 * SettingString表欄位值
		 * @param slotID
		 */
		SettingString(formId: number): string;
		/**
		 * 商城String表欄位值
		 * @param formId
		 */
		ShopString(formId: number): string;
		/**
		 * 信件String表欄位值
		 * @param formId
		 */
		MailString(formId: number): string;
		/**
		 * 活動String表欄位值
		 * @param formId
		 */
		EventString(formId: number): string;
		/**
		 * 信件String表欄位值
		 * @param formId
		 */
		CSSMailString(formId: number): string;
		/**
		 * 判斷表存不存在
		 * @param jsonFileName
		 * @param sheetName
		 */
		CheckTableExist(settingName: string, classSheetName: string): any;
		CheckTableIdExist(table: any, id: number): any;
		CheckGetValue(con: any, keyStr: string): any;
		/**
		 * 取得廳館名稱
		 * @param hallType HallType
		 */
		GetHallName(hallType: number): string;
	}
}

CSSettingsSDV3.prototype.CheckTableExist = function (settingName: string, classSheetName: string): any {
	let table = CSSettingsSDV3[settingName];
	if (table) {
		if (classSheetName !== "") {
			table = table[classSheetName];
			if (!table) {
				table = CSSettingsSDV3[settingName + BusinessTypeSetting.TYPE_BUSINESS];
				if (classSheetName !== "") {
					table = table[classSheetName];
				}
			}
		}
	} else {
		table = CSSettingsSDV3[settingName + BusinessTypeSetting.TYPE_BUSINESS];
		if (classSheetName !== "") {
			table = table[classSheetName];
		}
	}
	if (table) {
		return table;
	}
	console.warn("未知的表:" + settingName + "," + classSheetName);
	return null;
};

CSSettingsSDV3.prototype.CheckTableIdExist = function (table: any, id: number): any {
	if (table) {
		let con = table[id];
		if (con != null && con !== undefined) {
			return con;
		}
		console.warn(table["__proto__"]["constructor"]["name"] + "未知的ID:" + id);
	}
	return null;
};

CSSettingsSDV3.prototype.CheckGetValue = function (con: any, keyStr: string): any {
	if (con) {
		let con2 = con[keyStr];
		if (con2 != null && con2 !== undefined) {
			return con2;
		}
		console.warn(con["__proto__"]["constructor"]["name"] + "取不到ID" + con["Id"] + "欄位的KEY值:" + keyStr);
	}
	return null;
};

CSSettingsSDV3.prototype.CommonString = function (formId: number): string {
	const table = CSSettingsSDV3.String;
	if (!table) {
		return "";
	}
	let con = CSSettingsSDV3.prototype.CheckTableIdExist(table, formId);
	let value: string = CSSettingsSDV3.prototype.CheckGetValue(con, LanguageManager.GetMsgId());
	if (value) {
		value = value.replace("\\n", "\n");
		return value;
	}
	return "";
};

CSSettingsSDV3.prototype.RankString = function (formId: number): string {
	let table = CSSettingsSDV3.Rank.String;
	let con = CSSettingsSDV3.prototype.CheckTableIdExist(table, formId);
	let value: string = CSSettingsSDV3.prototype.CheckGetValue(con, LanguageManager.GetMsgId());
	if (value) {
		value = value.replace("\\n", "\n");
		return value;
	}
	return "";
};

CSSettingsSDV3.prototype.EventString = function (formId: number): string {
	let table = CSSettingsSDV3.Event.String;
	let con = CSSettingsSDV3.prototype.CheckTableIdExist(table, formId);
	let value: string = CSSettingsSDV3.prototype.CheckGetValue(con, LanguageManager.GetMsgId());
	if (value) {
		value = value.replace("\\n", "\n");
		return value;
	}
	return "";
};

CSSettingsSDV3.prototype.VipString = function (formId: number): string {
	let table = CSSettingsSDV3.Vip.String;
	let con = CSSettingsSDV3.prototype.CheckTableIdExist(table, formId);
	let value: string = CSSettingsSDV3.prototype.CheckGetValue(con, LanguageManager.GetMsgId());
	if (value) {
		value = value.replace("\\n", "\n");
		return value;
	}
	return "";
};

CSSettingsSDV3.prototype.PacketString = function (formId: number): string {
	let table = CSSettingsSDV3.Packet.String;
	let con = CSSettingsSDV3.prototype.CheckTableIdExist(table, formId);
	let value: string = CSSettingsSDV3.prototype.CheckGetValue(con, LanguageManager.GetMsgId());
	if (value) {
		value = value.replace("\\n", "\n");
		return value;
	}
	return "";
};

CSSettingsSDV3.prototype.ChatString = function (formId: number): string {
	let table = CSSettingsSDV3.Chat.String;
	let con = CSSettingsSDV3.prototype.CheckTableIdExist(table, formId);
	let value: string = CSSettingsSDV3.prototype.CheckGetValue(con, LanguageManager.GetMsgId());
	if (value) {
		value = value.replace("\\n", "\n");
		return value;
	}
	return "";
};

CSSettingsSDV3.prototype.CommunityString = function (formId: number): string {
	let table = CSSettingsSDV3.Community.String;
	let con = CSSettingsSDV3.prototype.CheckTableIdExist(table, formId);
	let value: string = CSSettingsSDV3.prototype.CheckGetValue(con, LanguageManager.GetMsgId());
	if (value) {
		value = value.replace("\\n", "\n");
		return value;
	}
	return "";
};

CSSettingsSDV3.prototype.GiftString = function (formId: number): string {
	let table = CSSettingsSDV3.Gift.String;
	let con = CSSettingsSDV3.prototype.CheckTableIdExist(table, formId);
	let value: string = CSSettingsSDV3.prototype.CheckGetValue(con, LanguageManager.GetMsgId());
	if (value) {
		value = value.replace("\\n", "\n");
		return value;
	}
	return "";
};

CSSettingsSDV3.prototype.TaskString = function (formId: number): string {
	let table = CSSettingsSDV3.Task.String;
	let con = CSSettingsSDV3.prototype.CheckTableIdExist(table, formId);
	let value: string = CSSettingsSDV3.prototype.CheckGetValue(con, LanguageManager.GetMsgId());
	if (value) {
		value = value.replace("\\n", "\n");
		return value;
	}
	return "";
};

CSSettingsSDV3.prototype.LobbyString = function (formId: number): string {
	let table = CSSettingsSDV3.Lobby.String;
	let con = CSSettingsSDV3.prototype.CheckTableIdExist(table, formId);
	let value: string = CSSettingsSDV3.prototype.CheckGetValue(con, LanguageManager.GetMsgId());
	if (value) {
		value = value.replace("\\n", "\n");
		return value;
	}
	return "";
};

CSSettingsSDV3.prototype.MailString = function (formId: number): string {
	let table = CSSettingsSDV3.Mail.String;
	let con = CSSettingsSDV3.prototype.CheckTableIdExist(table, formId);
	let value: string = CSSettingsSDV3.prototype.CheckGetValue(con, LanguageManager.GetMsgId());
	if (value) {
		value = value.replace("\\n", "\n");
		return value;
	}
	return "";
};

CSSettingsSDV3.prototype.LpPointString = function (formId: number): string {
	let table = CSSettingsSDV3.Lppoint.String;
	let con = CSSettingsSDV3.prototype.CheckTableIdExist(table, formId);
	let value: string = CSSettingsSDV3.prototype.CheckGetValue(con, LanguageManager.GetMsgId());
	if (value) {
		value = value.replace("\\n", "\n");
		return value;
	}
	return "";
};

CSSettingsSDV3.prototype.CSSMailString = function (formId: number): string {
	let table = CSSettingsSDV3.Mail.StringMail;
	let con = CSSettingsSDV3.prototype.CheckTableIdExist(table, formId);
	let value: string = CSSettingsSDV3.prototype.CheckGetValue(con, LanguageManager.GetMsgId());
	if (value) {
		value = value.replace("\\n", "\n");
		return value;
	}
	return "";
};

CSSettingsSDV3.prototype.SettingString = function (formId: number): string {
	let table = CSSettingsSDV3.Setting.String;
	let con = CSSettingsSDV3.prototype.CheckTableIdExist(table, formId);
	let value: string = CSSettingsSDV3.prototype.CheckGetValue(con, LanguageManager.GetMsgId());
	if (value) {
		value = value.replace("\\n", "\n");
		return value;
	}
	return "";
};

CSSettingsSDV3.prototype.ShopString = function (formId: number): string {
	let table = CSSettingsSDV3.Shop.String;
	let con = CSSettingsSDV3.prototype.CheckTableIdExist(table, formId);
	let value: string = CSSettingsSDV3.prototype.CheckGetValue(con, LanguageManager.GetMsgId());
	if (value) {
		value = value.replace("\\n", "\n");
		return value;
	}
	return "";
};

CSSettingsSDV3.prototype.GetHallName = function (hallType: number): string {
	return CSSettingsSDV3.prototype.LobbyString(hallType + 1);
};