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

read(41701, _) ->
    {ok, []};
read(41702, Bin0) ->
    <<QuizId:32, Bin1/binary>> = Bin0, 
    <<Answer:8, _Bin2/binary>> = Bin1, 
    {ok, [QuizId, Answer]};
read(41704, _) ->
    {ok, []};
read(41706, _) ->
    {ok, []};
read(_Cmd, _R) -> {error, no_match}.

write (41700,[
    Sid,
    TriggerCount
] = Src_Data) ->
    Data = <<
        Sid:8,
        TriggerCount:8
    >>,
    {ok, pt:encode(41700, Data, Src_Data)};

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

write (41702,[
    Res,
    QuizId,
    Answer,
    SuccessQuiz
] = Src_Data) ->
    Data = <<
        Res:32,
        QuizId:32,
        Answer:8,
        SuccessQuiz:8
    >>,
    {ok, pt:encode(41702, Data, Src_Data)};

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

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

write (41705,[
    QuizId,
    Index,
    Sid,
    SuccessQuiz
] = Src_Data) ->
    Data = <<
        QuizId:32,
        Index:8,
        Sid:64,
        SuccessQuiz:8
    >>,
    {ok, pt:encode(41705, Data, Src_Data)};

write (41706,[
    Sid,
    BossId,
    BossPower
] = Src_Data) ->
    Data = <<
        Sid:8,
        BossId:32,
        BossPower:64
    >>,
    {ok, pt:encode(41706, Data, Src_Data)};

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


