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 lombok.extern.slf4j.Slf4j;

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

@Slf4j
public class OpenBooster extends ClientRequestParser {
    @Override
    public void parse(BattleNetPacket packet, ClientRequestBody body, TcpConnection conn) throws Exception {
        // 226 BoosterContent
        log.info("BoosterContent: got");
        Protocol.Date d = Protocol.Date.newBuilder()
                .setYear(2023)
                .setMonth(1)
                .setDay(3)
                .setHours(0)
                .setMin(0)
                .setSec(0)
                .build();

        Protocol.BoosterContent response = Protocol.BoosterContent.newBuilder()
                .addList(Protocol.BoosterCard.newBuilder()
                        .setCardDef(Protocol.CardDef.newBuilder()
                                .setAsset(459)
                                .setPremium(1))
                        .setInsertDate(d))
                .addList(Protocol.BoosterCard.newBuilder()
                        .setCardDef(Protocol.CardDef.newBuilder()
                                .setAsset(457)
                                .setPremium(1))
                        .setInsertDate(d))
                .addList(Protocol.BoosterCard.newBuilder()
                        .setCardDef(Protocol.CardDef.newBuilder()
                                .setAsset(777)
                                .setPremium(1))
                        .setInsertDate(d))
                .addList(Protocol.BoosterCard.newBuilder()
                        .setCardDef(Protocol.CardDef.newBuilder()
                                .setAsset(459)
                                .setPremium(1))
                        .setInsertDate(d))
                .addList(Protocol.BoosterCard.newBuilder()
                        .setCardDef(Protocol.CardDef.newBuilder()
                                .setAsset(459)
                                .setPremium(0))
                        .setInsertDate(d))
                .build();

        Protocol.Notification n = generateNotification(226, response.toByteString(), response.getSerializedSize());

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

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

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