%%%-------------------------------------------------------------------
%%% @author  tyl
%%% @doc
%%%      成就 - 协议文件
%%% @end
%%% Created : 2021-03-15
%%%-------------------------------------------------------------------
-module(pp_achievement).

-include("server.hrl").
-include("achievement.hrl").
-include("def_module.hrl").
-include("def_vip.hrl").
-include("figure.hrl").
-include("errcode.hrl").
-include("common.hrl").

-export([handle/3]).

handle(Cmd, Player, Data) ->
    #player_status{figure = Figure} = Player,
    OpenLv = lib_module:get_open_lv(?MOD_ACHIEVEMENT),
    case Figure#figure.lv >= OpenLv of
        true ->
            do_handle(Cmd, Player, Data);
        false -> skip
    end.

%% 获取大类信息
do_handle(40901, Player, []) ->
    lib_achievement:send_type_progress(Player#player_status.id),
    ok;

%% 获取成就列表
do_handle(40902, Player, [Type]) ->
    #player_status{id = RoleId} = Player,
    lib_achievement:send_achievement_list(RoleId, Type),
    ok;

%% 领取成就奖励
do_handle(40903, Player, [Type, SubType, Id]) ->
    NewPlayer = lib_achievement:receive_reward(Player, Type, SubType, Id),
    {ok, NewPlayer};

%% 获取成就等级经验
do_handle(40906, Player, []) ->
    lib_achievement:send_achievement_lv_info(Player),
    ok;

%% 获取成就特权信息
do_handle(40907, Player, []) ->
   lib_achievement:send_achievement_privilege_info(Player),
    ok;

%% 领取成就特权奖励
do_handle(40908, Player, [Lv]) ->
    NewPlayer = lib_achievement:receive_privilege_reward(Player, Lv),
    {ok, NewPlayer};

%% 成就特权:交易券兑换情况
do_handle(40910, Player, []) ->
    % #player_status{id = RoleId, sid = Sid} = Player,
    % NowCount = lib_daily:get_count(RoleId, ?MOD_ACHIEVEMENT, 1),
    % case data_achievement:get_stage_privilege_cfg(?ACHV_EXCHANGE_LV) of
    %    #stage_privilege_cfg{content = {_, _, NormalCount}} ->
    %        AddCount = lib_vip_api:get_vip_privilege(Player, ?VIP_ACHIEVEMENT_EXCHANGE, 1),
    %        MaxCount = NormalCount + AddCount,
    %        lib_server_send:send_to_sid(Sid, pt_409, 40910, [NowCount, MaxCount]);
    %    _ ->
    %        lib_server_send:send_to_sid(Sid, pt_409, 40909, [?ERRCODE(err409_config_err)])
    % end,
    {ok, Player};

%% 成就特权:红钻兑换交易券
do_handle(40911, Player, [Count]) when Count > 0 ->
    % lib_achievement:achievement_privilege_exchange(Player, Count);
    {ok, Player};

%% 每周固定奖励信息/领取周固定奖励
do_handle(40912, Player, [_Type]) ->
    % case Type of
    %    1 ->
    %        lib_achievement:weekly_reward_info(Player);
    %    2 ->
    %        lib_achievement:receive_weekly_reward(Player);
    %    _ ->
    %        {ok, Player}
    % end;
    {ok, Player};

do_handle(_Cmd, _Player, _Data) ->
    {error, "pp_achievement no match~n"}.