import api from './api.js'

const fetch = (key, data = {}, transform = true, loadingTitle, disabledToast = false) => {
  return new Promise((resolve, reject) => {
    
    const callback = (res) => {
      if (!transform) {
        resolve(res)
        return
      }
      if (res.code == 200) {
        resolve(res.result)
      } else {
        reject(res)
      }
    }

    api(key, data, callback, loadingTitle, disabledToast)
  })
}

export default fetch
