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

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

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

public class GetBattlePayStatus extends ClientRequestParser {
    @Override
    public void parse(BattleNetPacket packet, ClientRequestBody body, TcpConnection conn) throws Exception {
        byte[] b = Util.hexStringToByteArray("0A090A02696412031889020A0F0A0570726F746F1206320408002001");
        Protocol.Header header = Processor.generateResponse(b.length, packet.getHeader().getToken(), 0, 0);
        conn.send(new BattleNetPacket(header, b));

        Protocol.BattlePayStatusResponse response = Protocol.BattlePayStatusResponse.newBuilder()
                .setStatus(Protocol.BattlePayStatusResponse.PurchaseState.PS_READY)
                .setBattlePayAvailable(true)
                .build();

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

        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 255;
    }
}
