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

public class ClientOptions extends GenericParser {

    @Override
    public void parseGenericRequest(int token, TcpConnection conn) throws Exception {
        Protocol.ClientOptions clientOptions = Protocol.ClientOptions.newBuilder()
                .addOptions(Protocol.ClientOption.newBuilder()
                        .setIndex(24)
                        .setAsInt32(3))
                .addOptions(Protocol.ClientOption.newBuilder()
                        .setIndex(1)
                        .setAsUint64(13514148956663808L))
                .addOptions(Protocol.ClientOption.newBuilder()
                        .setIndex(2)
                        .setAsUint64(549755813888L))
                .addOptions(Protocol.ClientOption.newBuilder()
                        .setIndex(20)
                        .setAsInt32(2))
                .addOptions(Protocol.ClientOption.newBuilder()
                        .setIndex(21)
                        .setAsInt32(1))
                .addOptions(Protocol.ClientOption.newBuilder()
                        .setIndex(8)
                        .setAsInt32(4))
                .addOptions(Protocol.ClientOption.newBuilder()
                        .setIndex(10)
                        .setAsInt32(1))
                .build();

        Protocol.Notification n = generateNotification(241, clientOptions.toByteString(), clientOptions.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 CLIENT_OPTIONS.getValue();
    }
}
