%% ---------------------------------------------------------------------------
%% @doc 巅峰竞技跨服中心排行榜
%% @author hek
%% @since  2016-11-14
%% @deprecated
%% ---------------------------------------------------------------------------
-module(mod_top_pk_rank_center).
-behaviour(gen_server).
-include("common.hrl").
-include("top_pk.hrl").
-include("def_gen_server.hrl").

%% API
-export([start_link/0, stop/0, apply_cast/1, daily_update/0]).
%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).

start_link() ->
    gen_server:start_link({local,?MODULE}, ?MODULE, [], []).
stop() ->
    gen_server:call(?MODULE, 'stop').
apply_cast(Msg) ->
    gen_server:cast(?MODULE, Msg).
daily_update() ->
    apply_cast('daily_update').

init(Args) ->
    ?DO_INIT(Args).
handle_call(Request, From, State) ->
    ?DO_HANDLE_CALL(Request, From, State).
handle_cast(Msg, State) ->
    ?DO_HANDLE_CAST(Msg, State).
handle_info(Info, State) ->
    ?DO_HANDLE_INFO(Info, State).
terminate(Reason, State) ->
    ?DO_TERMINATE(Reason, State).
code_change(OldVsn, State, Extra) ->
    ?DO_CODE_CHANGE(OldVsn, State, Extra).

do_init([]) ->
    process_flag(trap_exit, true),
    {ok, State} = lib_top_pk_rank_center_mod:init(),
    {ok, State}.
do_handle_call('stop', _From, #rank_center_state{is_db = 1} = State) ->
    lib_top_pk_rank_center_mod:save_rank_center(State),
    {reply, ok, State#rank_center_state{is_db = 0}};
do_handle_call(_Request, _From, State) ->
    {reply, ok, State}.

do_handle_cast({'sync_rank_info', Node}, State) ->
    lib_top_pk_rank_center_mod:sync_rank_info(State, Node),
    {noreply, State};
do_handle_cast({'get_rank_info', Node, PlayerId, Page, PageSize}, State) ->
    lib_top_pk_rank_center_mod:get_rank_info(State, Node, PlayerId, Page, PageSize),
    {noreply, State};
do_handle_cast({'upload_rank_to_center', Msg}, State) ->
    {ok, NewState} = lib_top_pk_rank_center_mod:upload_rank_to_center(State, Msg),
    {noreply, NewState};
do_handle_cast({'refresh_rank', RankRole}, State) ->
    {ok, NewState} = lib_top_pk_rank_center_mod:refresh_rank(State, RankRole),
    {noreply, NewState};
do_handle_cast('act_end', State) ->
    NewState = lib_top_pk_rank_center_mod:act_end(State),
    {noreply, NewState};
do_handle_cast('daily_update', State) ->
    {ok, NewState} = lib_top_pk_rank_center_mod:daily_update(State),
    {noreply, NewState};
do_handle_cast({'update_role', RoleId, KeyValueList}, State) ->
    {ok, NewState} = lib_top_pk_rank_center_mod:update_role(State, RoleId, KeyValueList),
    {noreply, NewState};
do_handle_cast({'gm_season_end'}, State) ->
    {ok, NewState} = lib_top_pk_rank_center_mod:gm_season_end(State),
    {noreply, NewState};
do_handle_cast(_Msg, State) ->
    ?ERR("unkown msg:~p~n", [_Msg]),
    {noreply, State}.

do_handle_info('sync_rank', State) ->
    lib_top_pk_rank_center_mod:sync_rank(State),
    {noreply, State};
do_handle_info('save_rank_center', State) ->
    lib_top_pk_rank_center_mod:save_rank_center(State),
    {noreply, State#rank_center_state{is_db = 0}};
do_handle_info(_Info, State) ->
    {noreply, State}.
do_terminate(_Reason, #rank_center_state{is_db = IsDB} = State) ->
    case IsDB of
        1 -> lib_top_pk_rank_center_mod:save_rank_center(State);
        _ -> skip
    end,
    ok.
do_code_change(_OldVsn, State, _Extra) ->
    {ok, State}.

%% --------------------------------------------------------------------------
%%% Internal functions
%% --------------------------------------------------------------------------

