package com.bytesw.bytebot.service.provider;

import com.bytesw.xdf.exception.NotFoundException;
import com.twilio.exception.AuthenticationException;
import lombok.extern.log4j.Log4j2;

import java.util.HashMap;
import java.util.Map;

@Log4j2
public abstract class ProviderService {

    abstract void completeData(Map<String, Object> info, String SmsId, int Agent_id) throws Exception;

    public Map<String, Object> generateInfo(String sid, Map<String, Object> params) throws AuthenticationException {

        Map<String, Object> info = new HashMap<>();
        if (params == null) {
            return info;
        }
        try {
            int agen_id = (Integer) params.get("agent_id");
            this.completeData(info, sid, agen_id);
        } catch (NotFoundException e) {
            throw new NotFoundException(e.getMessage());
        } catch (java.lang.ClassCastException e) {
            log.info("Body Input inválido");
            throw new ClassCastException("Input inválido");
        } catch (AuthenticationException e) {
            throw new AuthenticationException(e.getMessage());
        } catch (InternalError e) {
            throw new InternalError(e.getMessage());
        } catch (Exception e) {
            throw new InternalError(e.getMessage());
        }

        return info;
    }
}
