/* Debugging */
if (typeof wiiu === 'undefined') {
	window.wiiu = {
		gamepad: {
			update: function () {
				return true;
			},
			hold: 0
		}
	};
}
// ローカル開発用に 各独自 API をエミュレート
// Emulate each proprietary API for local development
if (typeof wiiuBrowser === 'undefined') {
	window.wiiuBrowser = {
		closeApplication: function () {
			alert('アプリケーションは終了しました');
		},
		showLoadingIcon: function (show) {
			console.debug((show ? 'Show' : 'Hide') + ' loading icon');
		},
		endStartUp: function () {
			console.debug('endStartUp');
		},
		lockUserOperation: function (lock) {
			console.debug((lock ? 'Lock' : 'Unlock') + ' user operations');
		},
		lockHomeButtonMenu: function (lock) {
			console.debug((lock ? 'Lock' : 'Unlock') + ' home button menu');
		},
		canHistoryBack: function () {
			// とりあえずトップページなら履歴を戻れないということにしておく。
			return location.pathname !== '/';
		},
		setSwkbdDictionary: function (jsonString) {
			console.debug('Set SWKBD dictionary', JSON.parse(jsonString));
			return (Math.random() < 0.5)
				? {}
				: { error: { code: 111222, message: 'Test Error Message' } };
		},
		openTvAreaSetting: function () {
			alert('Tv側の安全フレーム設定画面を開きました');
		},
		jumpToBrowser: function (url) {
			console.debug(url);
		},
		jumpToEshop: function (query) {
			console.debug(query);
		},
		jumpToApplication: function (titleId, _flags, _communityId, _appData, _postId) {
			console.debug(titleId);
		}
	};
}
if (typeof wiiuDialog === 'undefined') {
	window.wiiuDialog = {
		alert: function (msg, btnStr) {
			alert(msg + '\n\n[ ' + btnStr + ' ]');
		},
		confirm: function (msg, lBtnStr, rBtnStr) {
			return confirm(msg + '\n\n[ ' + lBtnStr + ' (Cancel) ]  [ ' + rBtnStr + ' (OK) ]');
		}
	};
}
if (typeof wiiuSound === 'undefined') {
	window.wiiuSound = {
		playSound: function (soundId, device) {
			this.playSoundByName('id ' + soundId, device);
		},
		playSoundByName: function (name, _device) {
			console.debug('Play sound ' + name);
		}
	};
}
if (typeof wiiuDevice === 'undefined') {
	window.wiiuDevice = {
		isDrc: function () {
			return true;
		},
		getSKU: function () {
			return Math.random() < 7 / 8
				? { amount: 31205621760 }
				: { error: { code: 1112222, message: 'Test Error Message' } };
		},
		existsTitle: function () {
			return Math.random() < 1 / 2;
		}
	};
}
if (typeof wiiuSystemSetting === 'undefined') {
	window.wiiuSystemSetting = {
		checkParentalPinCode: function (code) {
			console.debug(code);
			return Math.random() < 0.5
				? { result: true }
				: {
						error: {
							code: 1112222,
							message: 'Test Error Message'
						}
					};
		},
		getRegion: function () {
			return Math.random() < 0.5
				? {
						code: 'JPN'
					}
				: {
						error: {
							code: 1112222,
							message: 'Test Error Message'
						}
					};
		},
		getCountry: function () {
			return Math.random() < 0.5
				? {
						code: 'JP'
					}
				: {
						error: {
							code: 1112222,
							message: 'Test Error Message'
						}
					};
		},
		getLanguage: function () {
			return Math.random() < 0.5
				? {
						code: 'ja'
					}
				: {
						error: {
							code: 1112222,
							message: 'Test Error Message'
						}
					};
		},
		getSpotPassUploadConsoleInfoState: function () {
			return { enable: Math.random() < 0.5 };
		}
	};
}
if (typeof wiiuBOSS === 'undefined') {
	window.wiiuBOSS = {
		isRegisteredBossTask: function () {
			console.debug('wiiuBOSS.isRegisteredBossTask');
			var result = {
				isRegistered: true
			};
			return result;
		},
		registerBossTask: function (_languageCode) {
			console.debug('wiiuBOSS.registerBossTask');
			// return { "error" : { "code" : 1112222, "message" : "Test Error Message"} };
			return {};
		},
		unregisterBossTask: function () {
			console.debug('wiiuBOSS.unregisterBossTask');
			// return { "error" : { "code" : 1112222, "message" : "Test Error Message"} };
			return {};
		},
		isRegisteredDirectMessageTask: function () {
			console.debug('wiiuBOSS.isRegisteredDirectMessageTask');
			var result = {
				isRegistered: true
			};
			return result;
		},
		registerDirectMessageTask: function (_languageCode) {
			console.debug('wiiuBOSS.registerDirectMessageTask');
			// return { "error" : { "code" : 1112222, "message" : "Test Error Message"} };
			return {};
		},
		registerDirectMessageTaskEx: function (_lifeTime, _interval) {
			console.debug('wiiuBOSS.registerDirectMessageTaskEx');
			// return { "error" : { "code" : 1112222, "message" : "Test Error Message"} };
			return {};
		},
		unregisterDirectMessageTask: function () {
			console.debug('wiiuBOSS.unregisterDirectMessageTask');
			// return { "error" : { "code" : 1112222, "message" : "Test Error Message"} };
			return {};
		}
	};
}
if (typeof wiiuMainApplication === 'undefined') {
	window.wiiuMainApplication = {
		_images: [
			// JPEG, 850x450, 暖色 warm color
			'[encoded data, 21812 characters]',
			// JPEG, 850x450, 寒色 cool
			'[encoded data, 21540 characters]',
			null
		],
		_getImage: function () {
			var images = this._images;
			var index = Math.floor(Math.random() * images.length);

			// テスト等でスクショの有無を固定したい場合にクッキーで指定できるようにする, 実機ではこの挙動は存在しない
			// If you want to fix the presence or absence of screenshots in tests, etc., make it possible to specify with cookies, this behavior does not exist on the actual device
			// var force = Olv.Cookie.get('force_screenshot_for_test');
			// if (force === 'true')  index = 0;
			// if (force === 'false') index = 2;

			return images[index];
		},
		getScreenShot: function (_isTv) {
			return this._getImage();
		},
		getAppData: function () {
			return null;
		},
		getExternalImageData: function () {
			return this._getImage();
		},
		getExternalBinaryData: function () {
			return null;
		}
	};
}
if (typeof wiiuMemo === 'undefined') {
	window.wiiuMemo = {
		_isFinish: true,
		open: function (reset) {
			console.debug('wiiuMemo.open(reset = ' + reset + ')');
			this._isFinish = false;
			var self = this;
			setTimeout(function () {
				self._isFinish = true;
			}, 100);
		},
		isFinish: function () {
			console.debug('wiiuMemo.isFinish()');
			console.debug(this._isFinish);
			return this._isFinish;
		},
		reset: function () {
			console.debug('wiiuMemo.reset()');
		},
		getImage: function (isTga) {
			console.debug('wiiuMemo.getImage(isTga = ' + isTga + ')');
			if (isTga) {
				return 'eJzt3FuO0zAUBuDCE8tgKSyL3YNGqFJpk9aX41v8fdK8MHXiy/HvZCR6u32/3f369vv288cfAAAAAAAAAAAAAAAAAAAAAABgK7fbbXQXALr7yr77D8BO5B+wI9kH7Ej2ATuSfcBuHnNP9gE7eM492QekOsqPFXJkxT4D83iXfTPm4ox9AtZVmoEtc2iFLAauLTobZ8tZgFwyD+CVnAMA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pmZSU7UXl9QhAJnUHI2aqr0ZqUNQs1BTVb9jpA5DTVX9npGqqpMaqao6qZGqqpMaqao6qZGqqpMaqao6qZGqqpMaqao6qZGqqpMaqao6qZGqqpMaqao6qZGqqpO6pE4DyLPUVP0Vl9SfAuSVgFyjpupoLqlDArInQCY1VUdwSe0WkN+k5llAvgJkoaZqz/Cf1O4A+Qk1nwDkFjVVe4T/pHYJyC1q9grINWqq9gT/SdULANlSU7UXI1UvokbNGpCqvRipejE1aiYgVXswUvUmaiYgVZ82UvVGaiYgVZ80UvVmaiYgVZ8yUlV1UiNVH6BmoabqU0aqPkRN1SeNVFWd1EhV1UmNVFWd1EhV1UmNVFWd1EhV1UmNVFWd1EhV1UmNVFWd1EhV1UmNVFWd1EhV1UmNVFWd1P8AJ/VddnyrN7kAAAAASUVORK5CYII=';
			}
		}
	};
}
if (typeof wiiuPDM === 'undefined') {
	window.wiiuPDM = {
		getTotalPlayTime: function (titleID) {
			console.debug('wiiuPDM.getTotalPlayTime(' + titleID + ')');
			return { minutes: 0 };
		},
		getTitlesFilteredByPlayTime: function (minutes) {
			console.debug('wiiuPDM.getTitlesFilteredByPlayTime(' + minutes + ')');
			return { IDs: [] };
		}
	};
}
if (typeof wiiuErrorViewer === 'undefined') {
	window.wiiuErrorViewer = {
		openByCode: function (errorCode) {
			var message = 'Message for error code ' + errorCode;
			this.openByCodeAndMessage(errorCode, message);
		},
		openByCodeAndMessage: function (errorCode, errorMessage) {
			alert(errorCode + '\n\n' + errorMessage);
		}
	};
}
if (typeof wiiuFilter === 'undefined') {
	window.wiiuFilter = {
		checkWord: function (message) {
			console.debug('Check words for message: ' + message);
			if (/[0-9]{6}/.test(message)) {
				return -1;
			}
			if (/ng word/i.test(message)) {
				return -2;
			}
			return 0;
		}
	};
}
if (typeof wiiuSessionStorage === 'undefined') {
	window.wiiuSessionStorage = {
		getItem: function (key) {
			return sessionStorage.getItem(key);
		},
		setItem: function (key, value) {
			sessionStorage.setItem(key, value);
			return true;
		},
		removeItem: function (key) {
			sessionStorage.removeItem(key);
		},
		clear: function () {
			sessionStorage.clear();
		},
		key: function (index) {
			return sessionStorage.key(index);
		},
		length: function () {
			return sessionStorage.length;
		}
	};
}
if (typeof wiiuLocalStorage === 'undefined') {
	window.wiiuLocalStorage = {
		getItem: function (key) {
			return localStorage.getItem(key);
		},
		setItem: function (key, value) {
			localStorage.setItem(key, value);
			return true;
		},
		removeItem: function (key) {
			localStorage.removeItem(key);
		},
		clear: function () {
			localStorage.clear();
		},
		key: function (index) {
			return localStorage.key(index);
		},
		length: function () {
			return localStorage.length;
		},
		write: function () { }
	};
}
