/* eslint-disable @typescript-eslint/no-explicit-any */
import { type InvalidateOptions, type InvalidateQueryFilters, isCancelledError, type QueryObserverResult, type RefetchOptions, type UseQueryReturnType } from "@tanstack/vue-query"
import { camelCase } from "change-case"
import { type Context, Effect, Exit, Hash, type Layer, type ManagedRuntime, S, Struct } from "effect-app"
import { type ApiClientFactory, type Req } from "effect-app/client"
import type { ExtractModuleName, RequestHandler, RequestHandlers, RequestHandlerWithInput, RequestInputFromMake, RequestsAny } from "effect-app/client/clientFor"
import type { InvalidationCallback } from "effect-app/client/makeClient"
import type * as ExitResult from "effect/Exit"
import { type Fiber } from "effect/Fiber"
import * as AsyncResult from "effect/unstable/reactivity/AsyncResult"
import { type ComputedRef, onBeforeUnmount, ref, type WatchSource } from "vue"
import { type Commander, CommanderStatic } from "./commander.js"
import { type I18n } from "./intl.js"
import { type CommanderResolved, makeUseCommand } from "./makeUseCommand.js"
import { makeMutation, type MutationOptionsBase, useMakeMutation } from "./mutate.js"
import { type CustomUndefinedInitialQueryOptions, makeQuery } from "./query.js"
import { makeRunPromise } from "./runtime.js"
import { type Toast } from "./toast.js"
const mapHandler = (
handler: Effect.Effect | ((i: I) => Effect.Effect),
map: (self: Effect.Effect, i: I) => Effect.Effect
) => Effect.isEffect(handler) ? map(handler, undefined as any) : (i: I) => map(handler(i), i)
// TODO: optimize - work from encoded shape directly
const projectHandler = (
handler: Effect.Effect | ((i: any) => Effect.Effect),
successSchema: S.Top,
projectionSchema: S.Top
) => {
const encode = S.encodeEffect(successSchema)
const decode = S.decodeEffectConcurrently(projectionSchema)
return mapHandler(handler, (self) =>
self.pipe(
Effect.flatMap(encode),
Effect.flatMap(decode)
))
}
const projectionSchemaHash = (schema: S.Top) => String(Hash.hash(schema.ast))
export interface CommandRequestExtensions