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 com.google.protobuf.ByteString;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class ResourcesProcessor extends Processor {

    public ResourcesProcessor() {
        this.setProcessorId(16);
    }

    @Override
    public void process(BattleNetPacket packet, TcpConnection conn) throws Exception {
        switch (packet.getHeader().getMethodId()) {
            case 1:
               // Protocol.ContentHandleRequest contentHandleRequest = Protocol.ContentHandleRequest.parseFrom(packet.getBody());
                Protocol.ContentHandle contentHandle = Protocol.ContentHandle.newBuilder()
                        .setRegion(17749)
                        .setUsage(1885762681)
                        .setHash(ByteString.copyFrom(Util.hexStringToByteArray("5b2f9b39434a1c4e3f970a76c1e97a8548c95da2ad52a6d37cf9d793dedd887d")))
                        .build();

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

                conn.send(new BattleNetPacket(header, contentHandle.toByteArray()));
                break;
            default:
                log.error("Can't process weird ResourcesProcessor method: " + packet.getHeader().getMethodId());
                break;
        }
    }

    @Override
    public String getExportName() {
        return "bnet.protocol.resources.Resources";
    }
}
