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.DECK_LIST;

public class DeckList extends GenericParser {

    @Override
    public void parseGenericRequest(int token, TcpConnection conn) throws Exception {
        Protocol.DeckList deckList = Protocol.DeckList.newBuilder()
                .addDecks(Protocol.DeckInfo.newBuilder()
                        .setId(794851023L)
                        .setName("The Fuck")
                        .setCardBack(0)
                        .setHero(637)
                        .setDeckType(Protocol.DeckType.NORMAL_DECK)
                        .setValidity(767L)
                        .setHeroPremium(0)
                        .setCardBackOverride(false)
                        .setHeroOverride(false)
                        .setLastModified(1461490210L)
                        .setSortOrder(1461490210L)
                        .setSourceType(Protocol.DeckSourceType.DECK_SOURCE_TYPE_BASIC_DECK))
                .addDecks(Protocol.DeckInfo.newBuilder()
                        .setId(794938262L)
                        .setName("The Cock")
                        .setCardBack(0)
                        .setHero(31)
                        .setDeckType(Protocol.DeckType.NORMAL_DECK)
                        .setValidity(767L)
                        .setHeroPremium(0)
                        .setCardBackOverride(false)
                        .setHeroOverride(false)
                        .setLastModified(1461490581L)
                        .setSortOrder(1461490581L)
                        .setSourceType(Protocol.DeckSourceType.DECK_SOURCE_TYPE_BASIC_DECK))
                .addDecks(Protocol.DeckInfo.newBuilder()
                        .setId(172325L)
                        .setName("precon")
                        .setCardBack(0)
                        .setHero(31)
                        .setDeckType(Protocol.DeckType.PRECON_DECK)
                        .setValidity(31L)
                        .setHeroPremium(0)
                        .setCardBackOverride(false)
                        .setHeroOverride(false)
                        .setSortOrder(0L)
                        .setSourceType(Protocol.DeckSourceType.DECK_SOURCE_TYPE_UNKNOWN))
                .addDecks(Protocol.DeckInfo.newBuilder()
                        .setId(171593L)
                        .setName("precon")
                        .setCardBack(0)
                        .setHero(637)
                        .setDeckType(Protocol.DeckType.PRECON_DECK)
                        .setValidity(31L)
                        .setHeroPremium(0)
                        .setCardBackOverride(false)
                        .setHeroOverride(false)
                        .setSortOrder(0L)
                        .setSourceType(Protocol.DeckSourceType.DECK_SOURCE_TYPE_UNKNOWN))
                .build();

        Protocol.Notification n = generateNotification(202, deckList.toByteString(), deckList.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 DECK_LIST.getValue();
    }
}
