%% ---------------------------------------------------------------------------
%% @doc 配置检测脚本
%% @author hek
%% @since  2016-05-16
%% @deprecated 本模块提供配置检测脚本
%% ---------------------------------------------------------------------------
-module(check).
-compile(export_all).
-include("common.hrl").

%%% Note:
%%% 游戏节点脚本启动前，调用配置检测脚本，只有检测通过时才启动游戏节点
%%% Usage:
%%% 1.少量检测在本模块新增一个check方法，并添加到main/1，如check_husong_data/0
%%% 2.大量检测，另起一个模块，并添加到添加到main/1
main(_) ->
	ok = init_db(),
	ok = check_husong_data(),
	ok = check_sync_config_status(),
	ok.

init_db() ->
	Conf = "../config/gsrv.config",
	[DbHost, DbPort, DbUser, DbPass, DbName, DbEncode, _DBConns, _MaxConns, _IsDevTest]
		= db_upgrade:get_mysql(Conf),
	db:start(DbHost, DbPort, DbUser, DbPass, DbName, DbEncode, 10, 10),
	ok.

%% 检测护送配置
check_husong_data() ->
	% NpcList = lib_husong:get_kv_cfg(?CFG_KEY_HUSONG_NPC_LIST),
	% DayConfig = lib_husong:get_kv_cfg(?CFG_KEY_HUSONG_OPEN_DAY),
	% lists:foreach(
	% 	fun({ {MinOpenDay, MaxOpenDay}, SceneId, NpcId }) ->
	% 		{ {MinOpenDay, MaxOpenDay}, SceneId, NpcId }
	% 	end, NpcList),
	% lists:foreach(
	% 	fun({ {MinOpenDay, MaxOpenDay}, OpenDayList }) ->
	% 		{ {MinOpenDay, MaxOpenDay}, OpenDayList }
	% 	end, DayConfig),
	ok.

%% 检测开发环境下 配置同步状态（稳定同步速游服等）
check_sync_config_status() ->
	Sql = io_lib:format(<<"select count(*) from sync_config_status where cf_status = 0">>, []),
	Res = case db:get_one(Sql) of
		null -> true;
		Count -> Count=<0
	end,
	case Res of
		true -> ok;
		false -> throw({error, sync_config_status})
	end.

