%%%------------------------------------
%%% @Module  :  mod_draw_record_local
%%% @Author  :  lhy
%%% @Created :  2019-06-01
%%% @Description: 定制活动抽奖记录
%%%------------------------------------

-module(mod_draw_record_local).

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

-export([
          refresh_draw_reward_record/1
         ,send_draw_reward_record/4
         ,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(DrawRecord) ->
    gen_server:cast(?MODULE, {'refresh_draw_reward_record', DrawRecord}).

%% 发送记录
send_draw_reward_record(RoleId, Type, SubType, PersonalRecords) ->
    gen_server:cast(?MODULE, {'send_draw_reward_record', RoleId, Type, SubType, 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) ->
    State = lib_draw_record_mod_local:init(),
    {ok, State}.

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

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

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

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

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

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