package com.alterdekim.hearthhack.component.processor.client.request.generic;

import com.alterdekim.Protocol;
import com.alterdekim.hearthhack.component.TcpConnection;
import com.alterdekim.hearthhack.util.BattleNetPacket;

import static com.alterdekim.hearthhack.util.GameUtilities.generateNotification;
import static com.alterdekim.hearthhack.util.GetAccountInfoRequest.PLAYER_RECORD;

public class PlayerRecords extends GenericParser {

    @Override
    public void parseGenericRequest(int token, TcpConnection conn) throws Exception {
        Protocol.PlayerRecords playerRecords = Protocol.PlayerRecords.newBuilder()
                .addRecords(Protocol.PlayerRecord.newBuilder()
                        .setType(Protocol.GameType.GT_VS_AI)
                        .setWins(1)
                        .setLosses(0))
                .addRecords(Protocol.PlayerRecord.newBuilder()
                        .setType(Protocol.GameType.GT_VS_AI)
                        .setData(637)
                        .setWins(1)
                        .setLosses(0))
                .addRecords(Protocol.PlayerRecord.newBuilder()
                        .setType(Protocol.GameType.GT_TUTORIAL)
                        .setWins(6)
                        .setLosses(1))
                .addRecords(Protocol.PlayerRecord.newBuilder()
                        .setType(Protocol.GameType.GT_TUTORIAL)
                        .setData(637)
                        .setWins(1)
                        .setLosses(0))
                .addRecords(Protocol.PlayerRecord.newBuilder()
                        .setType(Protocol.GameType.GT_TUTORIAL)
                        .setData(1325)
                        .setWins(5)
                        .setLosses(1))
                .build();


        Protocol.Notification n = generateNotification(270, playerRecords.toByteString(), playerRecords.getSerializedSize());

        Protocol.Header header = Protocol.Header.newBuilder()
                .setServiceId(4)
                .setMethodId(1)
                .setToken(conn.nextToken())
                .setObjectId(0)
                .setSize(n.getSerializedSize())
                .setStatus(0)
                .build();

        conn.send(new BattleNetPacket(header, n.toByteArray()));
    }

    @Override
    public int getId() {
        return PLAYER_RECORD.getValue();
    }
}
