import { UltraFetch } from "@ultra-man/noa"

export enum RequestCodeState {
  SUCCESS = 0,
  ERROR = -1,
  SETTLE_TWO = 351,
  SETTLE_THREE = 352,
  LOGGED_IN_EXPIRED = 301,
  NOT_LOGGED_IN = 302,
  ACCOUNT_FROZEN = 303,
}

export const ultraFetch = new UltraFetch(
  {
    baseURL: import.meta.env.VITE_SERVICE_URL,
    // baseURL: "/api",
    headers: {
      "Content-Type": "application/json",
    },
    credentials: "include",
  },
  {
    reqHandler: (config) => {
      config.headers = {
        ...config.headers,
      }

      return config
    },
    resHandler: (response) => {
      if (response.code === RequestCodeState.SUCCESS) {
        return response
      } else {
        return
      }
    },
    errHandler: () => {},
  }
)
