/*
 * @Author: wjc
 * @Date: 2023-11-27 15:35:24
 * @LastEditors: LiZhiWei
 * @LastEditTime: 2026-01-15 17:52:25
 * @Description:
 */
import type { UseFetchOptions } from '#app'

export type _AsyncData<DataT, ErrorT> = {
  data: Ref<DataT | null>
  pending: Ref<boolean>
  refresh: (opts?: AsyncDataExecuteOptions) => Promise<void>
  execute: (opts?: AsyncDataExecuteOptions) => Promise<void>
  error: Ref<ErrorT | null>
}
interface AsyncDataExecuteOptions {
  dedupe?: boolean
}

export type IInterceptor = {
  onRequest?: UseFetchOptions<any>['onRequest']
  onRequestError?: UseFetchOptions<any>['onRequestError']
  onResponse?: UseFetchOptions<any>['onResponse']
  onResponseError?: UseFetchOptions<any>['onResponseError']
}

export interface IConfig {
  baseURL: any
  interceptor?: IInterceptor
}
type Methods = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'get' | 'post' | 'put' | 'delete'

export interface IOption<T> {
  url: string
  method?: Methods
  params?: any // query
  data?: any // body
  options?: UseFetchOptions<T>
}

export type RequestQueueItem<T = BasicResponse> = {
  url: string
  options: UseFetchOptions<T>
  resolve: (data: T) => void
  reject: (data: unknown) => void
}
