package com.alterdekim.hearthhack.component.processor;


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

@Slf4j
public class ChannelProcessor extends Processor {

    public ChannelProcessor() {
        this.setProcessorId(7);
    }

    @Override
    public void process(BattleNetPacket packet, TcpConnection conn) throws Exception {
        switch (packet.getHeader().getMethodId()) {
            case 1:
                Protocol.CISubscribeResponse ciSubscribeResponse = Protocol.CISubscribeResponse.getDefaultInstance();
                Protocol.Header header = Protocol.Header.newBuilder(packet.getHeader())
                                .setServiceId(254)
                                .setSize(0)
                                .build();
                conn.send(new BattleNetPacket(header, ciSubscribeResponse.toByteArray()));
                break;
            default:
                log.error("Can't process weird ChannelProcessor method: " + packet.getHeader().getMethodId());
                break;
        }
    }

    @Override
    public String getExportName() {
        return "bnet.protocol.channel.Channel";
    }
}
