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

read(50000, _) ->
    {ok, []};
read(50001, Bin0) ->
    <<AutoBuy:8, _Bin1/binary>> = Bin0, 
    {ok, [AutoBuy]};
read(50002, Bin0) ->
    <<IsDouble:8, _Bin1/binary>> = Bin0, 
    {ok, [IsDouble]};
read(50003, Bin0) ->
    <<Type:8, _Bin1/binary>> = Bin0, 
    {ok, [Type]};
read(50008, _) ->
    {ok, []};
read(50009, _) ->
    {ok, []};
read(_Cmd, _R) -> {error, no_match}.

write (50000,[
    ObjectId,
    ConvoyCounts,
    IsConvoy,
    EndTime,
    PrayVal,
    IsDouble
] = Src_Data) ->
    Data = <<
        ObjectId:32,
        ConvoyCounts:8,
        IsConvoy:8,
        EndTime:32,
        PrayVal:16,
        IsDouble:8
    >>,
    {ok, pt:encode(50000, Data, Src_Data)};

write (50001,[
    Code,
    ObjectId,
    PrayVal,
    RewardList
] = Src_Data) ->
    Bin_RewardList = pt:write_object_list(RewardList), 

    Data = <<
        Code:32,
        ObjectId:32,
        PrayVal:16,
        Bin_RewardList/binary
    >>,
    {ok, pt:encode(50001, Data, Src_Data)};

write (50002,[
    Code,
    ConvoyId,
    IsDouble
] = Src_Data) ->
    Data = <<
        Code:32,
        ConvoyId:32,
        IsDouble:8
    >>,
    {ok, pt:encode(50002, Data, Src_Data)};

write (50003,[
    Result,
    Type
] = Src_Data) ->
    Data = <<
        Result:32,
        Type:8
    >>,
    {ok, pt:encode(50003, Data, Src_Data)};

write (50004,[
    Result,
    Stage,
    ObjectId,
    ConvoyCounts
] = Src_Data) ->
    Data = <<
        Result:8,
        Stage:8,
        ObjectId:32,
        ConvoyCounts:8
    >>,
    {ok, pt:encode(50004, Data, Src_Data)};

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

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

write (50010,[
    RoleId,
    AngelId
] = Src_Data) ->
    Data = <<
        RoleId:64,
        AngelId:32
    >>,
    {ok, pt:encode(50010, Data, Src_Data)};

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


