package com.alterdekim.hearthhack.component.processor;


import com.alterdekim.Protocol;
import com.alterdekim.hearthhack.component.TcpConnection;
import com.alterdekim.hearthhack.util.BattleNetPacket;
import com.alterdekim.hearthhack.util.Util;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Slf4j
public class AccountProcessor extends Processor {

    public AccountProcessor() {
        this.setProcessorId(17);
    }

    @Override
    public void process(BattleNetPacket packet, TcpConnection conn) throws Exception {
        switch (packet.getHeader().getMethodId()) {
            case 30:
               // Protocol.GetAccountStateRequest getAccountStateRequest = Protocol.GetAccountStateRequest.parseFrom(packet.getBody());
              //  log.info(getAccountStateRequest.toString());

                Protocol.GetAccountStateResponse getAccountStateResponse = Protocol.GetAccountStateResponse
                        .newBuilder()
                        .setState(Protocol.AccountState.newBuilder()
                                .setAccountLevelInfo(Protocol.AccountLevelInfo.newBuilder()
                                        .setDefaultCurrency(4543826)
                                        .setPreferredRegion(1)
                                        .setCountry("SVK")
                                        .build())
                                .build())
                        .setTags(Protocol.AccountFieldTags.newBuilder()
                                .setAccountLevelInfoTag(-577802125).build())
                        .build();

                Protocol.Header header = Processor.generateResponse(getAccountStateResponse.getSerializedSize(), packet.getHeader().getToken(), 0, 0);

                conn.send(new BattleNetPacket(header, getAccountStateResponse.toByteArray()));
                break;
            case 34:
                Protocol.Header header1 = Processor.generateResponse(53, packet.getHeader().getToken(), 0, 0);
                conn.send(new BattleNetPacket(header1, Util.hexStringToByteArray("12331880B5B9F50E221F0A0D36322E3139372E3234332E383810CBA6011A0A4272617469736C617661280030003800409AE5A1B905")));
                break;
            default:
                log.error("Can't process weird AccountProcessor method: " + packet.getHeader().getMethodId());
                break;
        }
    }

    @Override
    public String getExportName() {
        return "bnet.protocol.account.AccountNotify";
    }
}
