package com.alterdekim.hearthhack.component.processor.client.request.generic;

import com.alterdekim.Protocol;
import com.alterdekim.hearthhack.component.TcpConnection;
import com.alterdekim.hearthhack.reflect.ReflectionLoader;
import com.alterdekim.hearthhack.util.GetAccountInfoRequest;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class GeneralGenericParser extends ReflectionLoader<GenericParser> {
    public GeneralGenericParser() {
        this.initReflect(GenericParser.class);
    }

    public void parseGenericRequest(int token, Protocol.UtilGenericRequest request, TcpConnection conn) {
        GetAccountInfoRequest req = GetAccountInfoRequest.parseFromInt(request.getRequestSubId());
        if( !this.getParsers().containsKey(req.getValue()) ) {
            log.warn("Unknown generic request: {}", req);
            return;
        }
        try {
            GenericParser parser = this.getParsers().get(req.getValue());
            parser.parseGenericRequest(token, conn);
        } catch (Exception e) {
            log.error(e.getMessage());
        }
    }
}
