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;

public class SubscriptionRequest extends ClientRequestParser {
    @Override
    public void parse(BattleNetPacket packet, ClientRequestBody body, TcpConnection conn) throws Exception {
        //body.getRoute()
        Protocol.UtilSubscribeResponse response = Protocol.UtilSubscribeResponse.newBuilder()
                .setRoute((int) (Math.random() * 100d))
                .setKeepAliveSecs(300)
                .setMaxResubscribeAttempts(0)
                .setPendingResponseTimeout(0)
                .setPendingSubscribeTimeout(15)
                .setRequestMaxWaitSecs(120)
                .build();
        Protocol.ClientResponse clResponse = Protocol.ClientResponse.newBuilder()
                .addAttribute(Protocol.Attribute.newBuilder()
                        .setName("id")
                        .setValue(Protocol.Variant.newBuilder()
                                .setIntValue(315)
                        ))
                .addAttribute(Protocol.Attribute.newBuilder()
                        .setName("proto")
                        .setValue(Protocol.Variant.newBuilder()
                                .setBlobValue(response.toByteString())
                        ))
                .build();

        Protocol.Header header = Processor.generateResponse(clResponse.getSerializedSize(), packet.getHeader().getToken(), 0, 0);
        conn.send(new BattleNetPacket(header, clResponse.toByteArray()));
    }

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