import type { QueryState } from "./Store"

export type CustomStoreActionParams = Record<string, unknown>

/** Callable params source — invoked on each query/write `execute()`. */
export type QueryParamsSubscriber = () => CustomStoreActionParams

/** Core query params: plain snapshot or subscriber (framework-agnostic). */
export type QueryParamsInput = CustomStoreActionParams | QueryParamsSubscriber
export type CustomStoreActionOptions = {
  immediate?: boolean
  cb?: Function // function to call when call finised -> execute für getAll
  useStore?: boolean // default true, ignores store and returns directly
  notify?: boolean // default true, disables notification/snackbar
  responseType?: string // i.e stream
  mode?: string //i.e cors for streaming
  useCache?: boolean
}

export type CustomStoreActionsPayload = {
  id?: String // if set this will used as the final namespace giver for the actionId, if not it will be a nanoId
  /** Plain object or subscriber function — resolved on each `execute()`. */
  params?: QueryParamsInput
  options?: CustomStoreActionOptions
  config?: any
}
export type QueryApiQuery = QueryState & {
  execute: (params?: Record<string, any>) => Promise<any>
}
export type DataApiMethods = {
  data: Object
  error: Object
  response: Object
  isLoading: Boolean
  execute: Function
  clear: Function
  remove: Function
}
export type QueryMethods = DataApiMethods & {
  uuids: Array<string>
  query: Object
}
