import axios, {
  AxiosInstance, AxiosPromise, AxiosResponse, AxiosInterceptorManager,
} from 'axios'
import { Api } from '@api'
import type * as Types from '@src/store/Api/ApiTypes'


// Funzione che smista la richiesta in base al metodo
async function sendRequest(url, method, mydata, myformdata = null, responsedata = null, options = null) {
  const actions = {
    get: () => Api.get(url, mydata, responsedata),
    post: () => Api.post(url, mydata, responsedata, options),
    postformdata: () => Api.postFormData(url, myformdata, responsedata),
    delete: () => Api.Delete(url, mydata, responsedata),
    put: () => Api.put(url, mydata, responsedata),
    patch: () => Api.patch(url, mydata, responsedata),
  };
  const key = method.toLowerCase();
  if (actions[key]) return await actions[key]();
  throw new Error(`Metodo non supportato: ${method}`);
}

export default sendRequest
