-module(pt_463).
-include("common.hrl").
-export([
        read/2,
        write/2
    ]).

read(46300, _) ->
    {ok, []};
read(46301, _) ->
    {ok, []};
read(46302, Bin0) ->
    <<Type:8, _Bin1/binary>> = Bin0, 
    {ok, [Type]};
read(46303, _) ->
    {ok, []};
read(46305, _) ->
    {ok, []};
read(46306, _) ->
    {ok, []};
read(_Cmd, _R) -> {error, no_match}.

write (46300,[
    Floor,
    LeftTime
] = Src_Data) ->
    Data = <<
        Floor:16,
        LeftTime:32
    >>,
    {ok, pt:encode(46300, Data, Src_Data)};

write (46301,[
    StrengthList
] = Src_Data) ->
    BinList_StrengthList = [
        item_to_bin_0(StrengthList_Item) || StrengthList_Item <- StrengthList
    ], 

    StrengthList_Len = length(StrengthList), 
    Bin_StrengthList = list_to_binary(BinList_StrengthList),

    Data = <<
        StrengthList_Len:16, Bin_StrengthList/binary
    >>,
    {ok, pt:encode(46301, Data, Src_Data)};

write (46302,[
    Res,
    StrengthList
] = Src_Data) ->
    BinList_StrengthList = [
        item_to_bin_1(StrengthList_Item) || StrengthList_Item <- StrengthList
    ], 

    StrengthList_Len = length(StrengthList), 
    Bin_StrengthList = list_to_binary(BinList_StrengthList),

    Data = <<
        Res:32,
        StrengthList_Len:16, Bin_StrengthList/binary
    >>,
    {ok, pt:encode(46302, Data, Src_Data)};

write (46303,[
    SumExp,
    RewardList
] = Src_Data) ->
    BinList_RewardList = [
        item_to_bin_2(RewardList_Item) || RewardList_Item <- RewardList
    ], 

    RewardList_Len = length(RewardList), 
    Bin_RewardList = list_to_binary(BinList_RewardList),

    Data = <<
        SumExp:64,
        RewardList_Len:16, Bin_RewardList/binary
    >>,
    {ok, pt:encode(46303, Data, Src_Data)};

write (46304,[
    Time,
    SumExp,
    RewardList
] = Src_Data) ->
    BinList_RewardList = [
        item_to_bin_3(RewardList_Item) || RewardList_Item <- RewardList
    ], 

    RewardList_Len = length(RewardList), 
    Bin_RewardList = list_to_binary(BinList_RewardList),

    Data = <<
        Time:32,
        SumExp:64,
        RewardList_Len:16, Bin_RewardList/binary
    >>,
    {ok, pt:encode(46304, Data, Src_Data)};

write (46305,[
    Res
] = Src_Data) ->
    Data = <<
        Res:32
    >>,
    {ok, pt:encode(46305, Data, Src_Data)};

write (46306,[
    Res
] = Src_Data) ->
    Data = <<
        Res:32
    >>,
    {ok, pt:encode(46306, Data, Src_Data)};

write(_Cmd, _R) -> ?DEBUG("no_match:~p,~p~n", [_Cmd, _R]), {ok, pt:pack(0, <<>>)}.


item_to_bin_0 ({
    Type,
    LeftTimes
}) ->
    Data = <<
        Type:8,
        LeftTimes:16
    >>,
    Data.
item_to_bin_1 ({
    Type,
    LeftTimes
}) ->
    Data = <<
        Type:8,
        LeftTimes:16
    >>,
    Data.
item_to_bin_2 ({
    RewardId,
    Num
}) ->
    Data = <<
        RewardId:32,
        Num:16
    >>,
    Data.
item_to_bin_3 ({
    RewardId,
    Num
}) ->
    Data = <<
        RewardId:32,
        Num:16
    >>,
    Data.
