import { ofetch } from 'ofetch'

const API = import.meta.env.VITE_BACKEND

export default async (api: string, value?: any) => {
  let fetch
  try {
    if (!value) {
      fetch = await ofetch(API + api, { parseResponse: JSON.parse, retry: 3, retryDelay: 500, retryStatusCodes: [400, 404, 405, 500, 502] })
    } else {
      fetch = await ofetch(`${API}${api}/${value}/fetch-data`, { parseResponse: JSON.parse, retry: 3, retryDelay: 500, retryStatusCodes: [400, 404, 405, 500, 502] })
    }

    return fetch
  } catch {
    return {}
  }
}
