package com.alterdekim.hearthhack.component.processor;

import com.alterdekim.Protocol;
import com.alterdekim.hearthhack.component.TcpConnection;
import com.alterdekim.hearthhack.reflect.AbstractParser;
import com.alterdekim.hearthhack.util.BattleNetPacket;
import com.alterdekim.hearthhack.util.Compute32;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@NoArgsConstructor
public abstract class Processor implements AbstractParser {

    @Setter
    private int processorId;

    public int getProcessorHash() { return Compute32.Hash(getExportName()); }

    public String getExportName() {
        return "";
    }

    public abstract void process(BattleNetPacket packet, TcpConnection conn) throws Exception;

    public static Protocol.Header generateResponse(Integer size, Integer token, Integer status, Integer object_id) {
        Protocol.Header.Builder b = Protocol.Header.newBuilder().setServiceId(254);
        if(size != null) b.setSize(size);
        if(token != null) b.setToken(token);
        if(status != null) b.setStatus(status);
        if(object_id != null) b.setObjectId(object_id);
        return b.build();
    }

    @Override
    public int getId() {
        return processorId;
    }
}
