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

public class HeroXP extends GenericParser {

    @Override
    public void parseGenericRequest(int token, TcpConnection conn) throws Exception {

        Protocol.HeroXP xp = Protocol.HeroXP.newBuilder()
                .addXpInfos(Protocol.HeroXPInfo.newBuilder()
                        .setClassId(2)
                        .setLevel(1)
                        .setCurrXp(0)
                        .setMaxXp(70)
                        .setNextReward(Protocol.NextHeroLevelReward.newBuilder()
                                .setLevel(2)
                                .setRewardCard(Protocol.ProfileNoticeRewardCard.newBuilder()
                                        .setCard(Protocol.CardDef.newBuilder()
                                                .setAsset(823)
                                                .setPremium(0))
                                        .setQuantity(2))
                        ))
                .addXpInfos(Protocol.HeroXPInfo.newBuilder()
                        .setClassId(3)
                        .setLevel(1)
                        .setCurrXp(0)
                        .setMaxXp(70)
                        .setNextReward(Protocol.NextHeroLevelReward.newBuilder()
                                .setLevel(2)
                                .setRewardCard(Protocol.ProfileNoticeRewardCard.newBuilder()
                                        .setCard(Protocol.CardDef.newBuilder()
                                                .setAsset(437)
                                                .setPremium(0))
                                        .setQuantity(2))
                        ))
                .addXpInfos(Protocol.HeroXPInfo.newBuilder()
                        .setClassId(4)
                        .setLevel(2)
                        .setCurrXp(12)
                        .setMaxXp(80)
                        .setNextReward(Protocol.NextHeroLevelReward.newBuilder()
                                .setLevel(4)
                                .setRewardCard(Protocol.ProfileNoticeRewardCard.newBuilder()
                                        .setCard(Protocol.CardDef.newBuilder()
                                                .setAsset(1084)
                                                .setPremium(0))
                                        .setQuantity(2))
                        ))
                .addXpInfos(Protocol.HeroXPInfo.newBuilder()
                        .setClassId(5)
                        .setLevel(1)
                        .setCurrXp(0)
                        .setMaxXp(70)
                        .setNextReward(Protocol.NextHeroLevelReward.newBuilder()
                                .setLevel(2)
                                .setRewardCard(Protocol.ProfileNoticeRewardCard.newBuilder()
                                        .setCard(Protocol.CardDef.newBuilder()
                                                .setAsset(847)
                                                .setPremium(0))
                                        .setQuantity(2))
                        ))
                .addXpInfos(Protocol.HeroXPInfo.newBuilder()
                        .setClassId(6)
                        .setLevel(1)
                        .setCurrXp(0)
                        .setMaxXp(70)
                        .setNextReward(Protocol.NextHeroLevelReward.newBuilder()
                                .setLevel(2)
                                .setRewardCard(Protocol.ProfileNoticeRewardCard.newBuilder()
                                        .setCard(Protocol.CardDef.newBuilder()
                                                .setAsset(1361)
                                                .setPremium(0))
                                        .setQuantity(2))
                        ))
                .addXpInfos(Protocol.HeroXPInfo.newBuilder()
                        .setClassId(7)
                        .setLevel(1)
                        .setCurrXp(0)
                        .setMaxXp(70)
                        .setNextReward(Protocol.NextHeroLevelReward.newBuilder()
                                .setLevel(2)
                                .setRewardCard(Protocol.ProfileNoticeRewardCard.newBuilder()
                                        .setCard(Protocol.CardDef.newBuilder()
                                                .setAsset(421)
                                                .setPremium(0))
                                        .setQuantity(2))
                        ))
                .addXpInfos(Protocol.HeroXPInfo.newBuilder()
                        .setClassId(8)
                        .setLevel(1)
                        .setCurrXp(0)
                        .setMaxXp(70)
                        .setNextReward(Protocol.NextHeroLevelReward.newBuilder()
                                .setLevel(2)
                                .setRewardCard(Protocol.ProfileNoticeRewardCard.newBuilder()
                                        .setCard(Protocol.CardDef.newBuilder()
                                                .setAsset(1171)
                                                .setPremium(0))
                                        .setQuantity(2))
                        ))
                .addXpInfos(Protocol.HeroXPInfo.newBuilder()
                        .setClassId(9)
                        .setLevel(1)
                        .setCurrXp(0)
                        .setMaxXp(70)
                        .setNextReward(Protocol.NextHeroLevelReward.newBuilder()
                                .setLevel(2)
                                .setRewardCard(Protocol.ProfileNoticeRewardCard.newBuilder()
                                        .setCard(Protocol.CardDef.newBuilder()
                                                .setAsset(982)
                                                .setPremium(0))
                                        .setQuantity(2))
                        ))
                .addXpInfos(Protocol.HeroXPInfo.newBuilder()
                        .setClassId(10)
                        .setLevel(1)
                        .setCurrXp(0)
                        .setMaxXp(70)
                        .setNextReward(Protocol.NextHeroLevelReward.newBuilder()
                                .setLevel(2)
                                .setRewardCard(Protocol.ProfileNoticeRewardCard.newBuilder()
                                        .setCard(Protocol.CardDef.newBuilder()
                                                .setAsset(940)
                                                .setPremium(0))
                                        .setQuantity(2))
                        ))
                .build();

        Protocol.Notification n = generateNotification(283, xp.toByteString(), xp.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 HERO_XP.getValue();
    }
}
