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

public class FavoriteHeroes extends GenericParser {

    @Override
    public void parseGenericRequest(int token, TcpConnection conn) throws Exception {
        Protocol.FavoriteHeroesResponse favoriteHeroesResponse = Protocol.FavoriteHeroesResponse.newBuilder()
                .addFavoriteHeroes(Protocol.FavoriteHero.newBuilder()
                        .setClassId(2)
                        .setHero(Protocol.CardDef.newBuilder()
                                .setAsset(274)
                                .setPremium(0)))
                .addFavoriteHeroes(Protocol.FavoriteHero.newBuilder()
                        .setClassId(3)
                        .setHero(Protocol.CardDef.newBuilder()
                                .setAsset(31)
                                .setPremium(0)))
                .addFavoriteHeroes(Protocol.FavoriteHero.newBuilder()
                        .setClassId(4)
                        .setHero(Protocol.CardDef.newBuilder()
                                .setAsset(637)
                                .setPremium(0)))
                .addFavoriteHeroes(Protocol.FavoriteHero.newBuilder()
                        .setClassId(5)
                        .setHero(Protocol.CardDef.newBuilder()
                                .setAsset(671)
                                .setPremium(0)))
                .addFavoriteHeroes(Protocol.FavoriteHero.newBuilder()
                        .setClassId(6)
                        .setHero(Protocol.CardDef.newBuilder()
                                .setAsset(813)
                                .setPremium(0)))
                .addFavoriteHeroes(Protocol.FavoriteHero.newBuilder()
                        .setClassId(7)
                        .setHero(Protocol.CardDef.newBuilder()
                                .setAsset(930)
                                .setPremium(0)))
                .addFavoriteHeroes(Protocol.FavoriteHero.newBuilder()
                        .setClassId(8)
                        .setHero(Protocol.CardDef.newBuilder()
                                .setAsset(1066)
                                .setPremium(0)))
                .addFavoriteHeroes(Protocol.FavoriteHero.newBuilder()
                        .setClassId(9)
                        .setHero(Protocol.CardDef.newBuilder()
                                .setAsset(893)
                                .setPremium(0)))
                .addFavoriteHeroes(Protocol.FavoriteHero.newBuilder()
                        .setClassId(10)
                        .setHero(Protocol.CardDef.newBuilder()
                                .setAsset(7)
                                .setPremium(0)))
                .build();

        Protocol.Notification n = generateNotification(318, favoriteHeroesResponse.toByteString(), favoriteHeroesResponse.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 FAVORITE_HEROES.getValue();
    }
}
