import type { RPC } from "./rpc";
import type { ApiRouterHandler } from "../http/ApiRouter";
import type { UnwrapPromise } from "../utils/type";
import type { UrlParser } from "./types";
type Methods = {
    POST: {
        [K in keyof RPC as K extends `POST:${infer P}` ? P : never]: RPC[K];
    };
    PUT: {
        [K in keyof RPC as K extends `PUT:${infer P}` ? P : never]: RPC[K];
    };
    PATCH: {
        [K in keyof RPC as K extends `PATCH:${infer P}` ? P : never]: RPC[K];
    };
    DELETE: {
        [K in keyof RPC as K extends `DELETE:${infer P}` ? P : never]: RPC[K];
    };
};
type Config<T> = {
    autoInvalidate?: boolean;
    onSuccess: (data: T) => void;
    onError: (error: MutationError) => void;
    onCanceled?: () => void;
};
type Data<M extends keyof Methods, K extends keyof Methods[M]> = Methods[M][K] extends ApiRouterHandler<any, infer T, any> ? UnwrapPromise<T> : never;
type Body<M extends keyof Methods, K extends keyof Methods[M]> = Methods[M][K] extends ApiRouterHandler<infer T, any, any> ? T : never;
type MutationError = {
    kind: "validation_error";
    messages: Record<string, any>;
} | {
    kind: "form_error";
    message: string;
} | {
    kind: "server_error";
    message: string;
} | {
    kind: "not_authorized";
    message: string;
} | {
    kind: "insufficient_permissions";
    message: string;
};
type ParseParams<T> = UrlParser<`${T & string}`>;
export declare function useMutation<M extends keyof Methods, K extends keyof Methods[M], T = Data<M, K>, U = Body<M, K>>(method: M, url: K, ...args: [
    options?: {
        params?: Partial<ParseParams<K>>;
        search?: Record<string, string>;
    },
    config?: Partial<Config<T>>
]): {
    data: T;
    error: any;
    loading: boolean;
    formData: FormData;
    cancel: () => void;
    trigger: {
        (input?: U): Promise<T>;
        formData(formData: FormData): Promise<T>;
    };
};
export declare function usePost<K extends keyof Methods["POST"], T = Data<"POST", K>>(url: K, ...args: [
    options?: {
        params?: Partial<ParseParams<K>>;
    },
    config?: Partial<Config<T>>
]): {
    data: Data<"POST", K>;
    error: any;
    loading: boolean;
    formData: FormData;
    cancel: () => void;
    trigger: {
        (input?: Body<"POST", K>): Promise<Data<"POST", K>>;
        formData(formData: FormData): Promise<Data<"POST", K>>;
    };
};
export declare function usePut<K extends keyof Methods["PUT"], T = Data<"PUT", K>>(url: K, ...args: [
    options?: {
        params?: Partial<ParseParams<K>>;
    },
    config?: Partial<Config<T>>
]): {
    data: Data<"PUT", K>;
    error: any;
    loading: boolean;
    formData: FormData;
    cancel: () => void;
    trigger: {
        (input?: Body<"PUT", K>): Promise<Data<"PUT", K>>;
        formData(formData: FormData): Promise<Data<"PUT", K>>;
    };
};
export declare function usePatch<K extends keyof Methods["PATCH"], T = Data<"PATCH", K>>(url: K, ...args: [
    options?: {
        params?: Partial<ParseParams<K>>;
    },
    config?: Partial<Config<T>>
]): {
    data: Data<"PATCH", K>;
    error: any;
    loading: boolean;
    formData: FormData;
    cancel: () => void;
    trigger: {
        (input?: Body<"PATCH", K>): Promise<Data<"PATCH", K>>;
        formData(formData: FormData): Promise<Data<"PATCH", K>>;
    };
};
export declare function useDelete<K extends keyof Methods["DELETE"], T = Data<"DELETE", K>>(url: K, ...args: [
    options?: {
        params?: Partial<ParseParams<K>>;
    },
    config?: Partial<Config<T>>
]): {
    data: Data<"DELETE", K>;
    error: any;
    loading: boolean;
    formData: FormData;
    cancel: () => void;
    trigger: {
        (input?: Body<"DELETE", K>): Promise<Data<"DELETE", K>>;
        formData(formData: FormData): Promise<Data<"DELETE", K>>;
    };
};
export declare function useUpload<K extends keyof Methods["POST"], T = Data<"POST", K>>(url: K, ...args: [
    options?: {
        params?: Partial<ParseParams<K>>;
    },
    config?: Partial<Config<T>>
]): {
    state: "done" | "error" | "idle" | "uploading";
    progress: number;
    trigger: (fileList: FileList | null | File) => Promise<T>;
    cancel: () => void;
};
export {};
//# sourceMappingURL=useMutation.d.ts.map