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

read(17700, _) ->
    {ok, []};
read(17701, _) ->
    {ok, []};
read(17702, Bin0) ->
    <<FishingRodId:32, Bin1/binary>> = Bin0,
    <<BaitId:32, _Bin2/binary>> = Bin1,
    {ok, [FishingRodId, BaitId]};
read(17703, Bin0) ->
    <<FishingGearId:32, Bin1/binary>> = Bin0,
    <<Count:32, _Bin2/binary>> = Bin1,
    {ok, [FishingGearId, Count]};
read(17704, Bin0) ->
    <<DistriSceneId:32, Bin1/binary>> = Bin0,
    <<SceneType:8, Bin2/binary>> = Bin1,
    <<HomeFishPondLv:32, Bin3/binary>> = Bin2,
    <<WaterArea:16, Bin4/binary>> = Bin3,
    <<MaunalOrAuto:16, _Bin5/binary>> = Bin4,
    {ok, [DistriSceneId, SceneType, HomeFishPondLv, WaterArea, MaunalOrAuto]};
read(17705, Bin0) ->
    <<Code:16, _Bin1/binary>> = Bin0,
    {ok, [Code]};
read(17706, _) ->
    {ok, []};
read(17714, Bin0) ->
    <<IlluId:32, _Bin1/binary>> = Bin0,
    {ok, [IlluId]};
read(17707, Bin0) ->
    <<DistriSceneId:32, _Bin1/binary>> = Bin0,
    {ok, [DistriSceneId]};
read(17708, _) ->
    {ok, []};
read(17709, _) ->
    {ok, []};
read(17710, Bin0) ->
    <<MaunalOrAuto:8, _Bin1/binary>> = Bin0,
    {ok, [MaunalOrAuto]};
read(17711, _) ->
    {ok, []};
read(17712, Bin0) ->
    <<ActId:8, _Bin1/binary>> = Bin0,
    {ok, [ActId]};
read(17713, _) ->
    {ok, []};
read(_Cmd, _R) -> {error, no_match}.

write (17700,[
    EnergyValue,
    Lv,
    Mastery
]) ->
    Data = <<
        EnergyValue:32,
        Lv:32,
        Mastery:32
    >>,
    {ok, pt:pack(17700, Data)};

write (17701,[
    FishingRod
]) ->
    BinList_FishingRod = [
        item_to_bin_0(FishingRod_Item) || FishingRod_Item <- FishingRod
    ],

    FishingRod_Len = length(FishingRod),
    Bin_FishingRod = list_to_binary(BinList_FishingRod),

    Data = <<
        FishingRod_Len:16, Bin_FishingRod/binary
    >>,
    {ok, pt:pack(17701, Data)};

write (17702,[
]) ->
    Data = <<
    >>,
    {ok, pt:pack(17702, Data)};

write (17703,[
]) ->
    Data = <<
    >>,
    {ok, pt:pack(17703, Data)};

write (17704,[
    RangeOfBalance,
    Recode,
    FishingRodId,
    UsageCount,
    BaitId,
    MaunalOrAuto
]) ->
    Data = <<
        RangeOfBalance:16,
        Recode:32,
        FishingRodId:32,
        UsageCount:32,
        BaitId:32,
        MaunalOrAuto:16
    >>,
    {ok, pt:pack(17704, Data)};

write (17705,[
    FishId,
    FishingRodId
]) ->
    Data = <<
        FishId:32,
        FishingRodId:32
    >>,
    {ok, pt:pack(17705, Data)};

write (17706,[
    Length,
    SumComat,
    IlluList
]) ->
    BinList_IlluList = [
        item_to_bin_1(IlluList_Item) || IlluList_Item <- IlluList
    ],

    IlluList_Len = length(IlluList),
    Bin_IlluList = list_to_binary(BinList_IlluList),

    Data = <<
        Length:32,
        SumComat:32,
        IlluList_Len:16, Bin_IlluList/binary
    >>,
    {ok, pt:pack(17706, Data)};

write (17714,[
    IlluId,
    IlluLv,
    Length,
    Combat
]) ->
    Data = <<
        IlluId:32,
        IlluLv:32,
        Length:32,
        Combat:32
    >>,
    {ok, pt:pack(17714, Data)};

write (17707,[
]) ->
    Data = <<
    >>,
    {ok, pt:pack(17707, Data)};

write (17708,[
    FishBasket
]) ->
    BinList_FishBasket = [
        item_to_bin_2(FishBasket_Item) || FishBasket_Item <- FishBasket
    ],

    FishBasket_Len = length(FishBasket),
    Bin_FishBasket = list_to_binary(BinList_FishBasket),

    Data = <<
        FishBasket_Len:16, Bin_FishBasket/binary
    >>,
    {ok, pt:pack(17708, Data)};

write (17709,[
    Rcode
]) ->
    Data = <<
        Rcode:32
    >>,
    {ok, pt:pack(17709, Data)};

write (17710,[
    Recode
]) ->
    Data = <<
        Recode:32
    >>,
    {ok, pt:pack(17710, Data)};

write (17711,[
    Recode
]) ->
    Data = <<
        Recode:32
    >>,
    {ok, pt:pack(17711, Data)};

write (17712,[
    RoleId,
    ActId,
    CenterX,
    CenterY
]) ->
    Data = <<
        RoleId:64,
        ActId:8,
        CenterX:32,
        CenterY:32
    >>,
    {ok, pt:pack(17712, Data)};

write (17713,[
    Recode
]) ->
    Data = <<
        Recode:32
    >>,
    {ok, pt:pack(17713, Data)};

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


item_to_bin_0 ({
    FishingRodId,
    UsageCount
}) ->
    Data = <<
        FishingRodId:32,
        UsageCount:32
    >>,
    Data.
item_to_bin_1 ({
    Id,
    Type,
    Lv,
    Combat
}) ->
    Data = <<
        Id:32,
        Type:16,
        Lv:32,
        Combat:32
    >>,
    Data.
item_to_bin_2 ({
    FishId,
    Count
}) ->
    Data = <<
        FishId:32,
        Count:32
    >>,
    Data.
