import type { useI18n } from "vue-i18n"
import type { ComputedRef, Ref } from "vue"
import type { PluginStoreApi, CorePluginApi } from "@racletteCore/types"
import type { VueQueryParamsInput, VueStoreActionsPayload } from "./DataApi"
import type { Query } from "@racletteCore/store/reducers/queries/reducers"
import type { actionId } from "@racletteCore"
import type { Socket } from "socket.io-client"
import type { User } from "@shared/types"
// TODO: finalize types
// TODO: generate this type from index.ts in the plugin & extend it globally
export type PluginMethod = (payload?: VueStoreActionsPayload) => {
  isLoading: Boolean
  response: Ref<unknown>
  error: Ref<unknown>
  data: ComputedRef<unknown>
  dataArr: Array<ComputedRef<unknown>>
  execute: (
    params?: VueQueryParamsInput,
  ) => Promise<{ response: any; result: any }>
  // query and uuids only provided from queryObservableHelper
  query?: ComputedRef<Query>
  uuids?: Array<string>
  // TODO: implement this in the useVueQueryObservableHelper remove: () => void
}
export type PluginSocketApi = {
  registeredListeners: Array<{ eventName: string; handlerFn: Function }>
  on: (eventName: string, handlerFn: Function) => Socket["on"]
  once: (eventName: string, handlerFn: Function) => Socket["once"]
  off: (eventName: string, handlerFn: Function) => Socket["off"]
  emit: (eventName: string, eventPayload: any) => Socket["emit"]
}
// TODO: get rid about the two types "PluginCoreApi" / "PluginApi"
export type PluginApi = {
  $eventbus?: any
  $globalEventbus?: any
  $user: ComputedRef<User>
  $store: PluginStoreApi
  $log: ReturnType<CorePluginApi["$log"]["plugin"]>
  $file: any
  $data: Record<string, Record<string, PluginMethod>>
  error: any
  $socket: PluginSocketApi
  $i18n: ReturnType<typeof useI18n>
}
export type PluginApiParams = {
  actionId?: actionId
  $data?: boolean
  $store?: boolean
  $eventbus?: boolean
  $socket?: boolean
  pluginKey?: string
}
