%%%------------------------------------
%%% @Module  :  mod_draw_record_kf
%%% @Author  :  lhy
%%% @Created :  2019-06-01
%%% @Description: 定制活动抽奖记录(跨服)
%%%------------------------------------

-module(mod_draw_record_kf).

-behaviour(gen_server).
-include("def_gen_server.hrl").
-include("common.hrl").
-include("custom_act_draw_record.hrl").

-export([
           refresh_draw_reward_record/1
          ,send_draw_reward_record/5
          ,act_end/2
    ]).

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

%%
refresh_draw_reward_record(KfDrawRecord) ->
    gen_server:cast(?MODULE, {'refresh_draw_reward_record', KfDrawRecord}).

%% 发送记录
send_draw_reward_record(RoleId, Type, SubType, ServerId, PersonalRecords) ->
    gen_server:cast(?MODULE, {'send_draw_reward_record', RoleId, Type, SubType, ServerId, PersonalRecords}).

%% 清除活动记录
act_end(Type, SubType) ->
    gen_server:cast(?MODULE, {'act_end', Type, SubType}).

%% -------------------------------------------------------------------------------------
start_link() ->
    gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).

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(Args) ->
    NewState = lib_draw_record_mod_kf:init(Args),
    {ok, NewState}.

%% ------------------------------------ handle call ------------------------------------
do_handle_call(_Request, _From, State) ->
    {reply, ok, State}.

%% ------------------------------------ handle cast ------------------------------------
do_handle_cast({'refresh_draw_reward_record', KfDrawRecord}, State) ->
    NewState = lib_draw_record_mod_kf:refresh_draw_reward_record(KfDrawRecord, State),
    {noreply, NewState};

do_handle_cast({'send_draw_reward_record', RoleId, Type, SubType, ServerId, PersonalRecords}, State) ->
    lib_draw_record_mod_kf:send_draw_reward_record(RoleId, Type, SubType, ServerId, PersonalRecords, State),
    {noreply, State};

do_handle_cast({'act_end', Type, SubType}, State) ->
    NewState = lib_draw_record_mod_kf:act_end(Type, SubType, State),
    {noreply, NewState};

do_handle_cast(_Msg, State) ->
    {noreply, State}.

%% ------------------------------------- handle info -----------------------------------
do_handle_info(_Info, State) ->
    {noreply, State}.

%% -------------------------------------------------------------------------------------
do_terminate(_Reason, _State) ->
    ok.
do_code_change(_OldVsn, State, _Extra) ->
    {ok, State}.