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

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

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

public class DeleteDeck extends ClientRequestParser {
    @Override
    public void parse(BattleNetPacket packet, ClientRequestBody body, TcpConnection conn) throws Exception {
        Protocol.DeleteDeck request = Protocol.DeleteDeck.parseFrom(body.getBody());
        conn.getUserService().deleteDeck(conn.getUserId(), request.getDeck());
        Protocol.DeckDeleted response = Protocol.DeckDeleted.newBuilder()
                .setDeck(request.getDeck())
                .build();

        byte[] b = generateNotification(218, response.toByteString(), response.getSerializedSize()).toByteArray();

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

        conn.send(new BattleNetPacket(header, b));
    }

    @Override
    public int getId() {
        return 210;
    }
}
