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

public class GoldBalance extends GenericParser {

    @Override
    public void parseGenericRequest(int token, TcpConnection conn) throws Exception {
        Protocol.GoldBalance gb = Protocol.GoldBalance.newBuilder()
                .setCap(999999)
                .setBonusBalance(0)
                .setCappedBalance(conn.getUserService().getGoldForUserId(conn.getUserId()))
                .setCapWarning(2000)
                .build();

        byte[] b = generateNotification(278, gb.toByteString(), gb.getSerializedSize()).toByteArray();

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

        conn.send(new BattleNetPacket(header, b));
    }

    @Override
    public int getId() {
        return GOLD_BALANCE.getValue();
    }
}
