// This file is auto-generated by @hey-api/openapi-ts

import {
	type Options,
	register,
	login,
	logout,
	getMe,
	getStatus,
	changePassword,
	listVolumes,
	createVolume,
	testConnection,
	deleteVolume,
	getVolume,
	updateVolume,
	getContainersUsingVolume,
	mountVolume,
	unmountVolume,
	healthCheckVolume,
	listFiles,
	browseFilesystem,
	listRepositories,
	createRepository,
	listRcloneRemotes,
	deleteRepository,
	getRepository,
	listSnapshots,
	getSnapshotDetails,
	listSnapshotFiles,
	restoreSnapshot,
	doctorRepository,
	listBackupSchedules,
	createBackupSchedule,
	deleteBackupSchedule,
	getBackupSchedule,
	updateBackupSchedule,
	getBackupScheduleForVolume,
	runBackupNow,
	stopBackup,
	getSystemInfo,
	downloadResticPassword,
} from "../sdk.gen";
import { queryOptions, type UseMutationOptions, type DefaultError } from "@tanstack/react-query";
import type {
	RegisterData,
	RegisterResponse,
	LoginData,
	LoginResponse,
	LogoutData,
	LogoutResponse,
	GetMeData,
	GetStatusData,
	ChangePasswordData,
	ChangePasswordResponse,
	ListVolumesData,
	CreateVolumeData,
	CreateVolumeResponse,
	TestConnectionData,
	TestConnectionResponse,
	DeleteVolumeData,
	DeleteVolumeResponse,
	GetVolumeData,
	UpdateVolumeData,
	UpdateVolumeResponse,
	GetContainersUsingVolumeData,
	MountVolumeData,
	MountVolumeResponse,
	UnmountVolumeData,
	UnmountVolumeResponse,
	HealthCheckVolumeData,
	HealthCheckVolumeResponse,
	ListFilesData,
	BrowseFilesystemData,
	ListRepositoriesData,
	CreateRepositoryData,
	CreateRepositoryResponse,
	ListRcloneRemotesData,
	DeleteRepositoryData,
	DeleteRepositoryResponse,
	GetRepositoryData,
	ListSnapshotsData,
	GetSnapshotDetailsData,
	ListSnapshotFilesData,
	RestoreSnapshotData,
	RestoreSnapshotResponse,
	DoctorRepositoryData,
	DoctorRepositoryResponse,
	ListBackupSchedulesData,
	CreateBackupScheduleData,
	CreateBackupScheduleResponse,
	DeleteBackupScheduleData,
	DeleteBackupScheduleResponse,
	GetBackupScheduleData,
	UpdateBackupScheduleData,
	UpdateBackupScheduleResponse,
	GetBackupScheduleForVolumeData,
	RunBackupNowData,
	RunBackupNowResponse,
	StopBackupData,
	StopBackupResponse,
	GetSystemInfoData,
	DownloadResticPasswordData,
	DownloadResticPasswordResponse,
} from "../types.gen";
import { client as _heyApiClient } from "../client.gen";

export type QueryKey<TOptions extends Options> = [
	Pick<TOptions, "baseUrl" | "body" | "headers" | "path" | "query"> & {
		_id: string;
		_infinite?: boolean;
		tags?: ReadonlyArray<string>;
	},
];

const createQueryKey = <TOptions extends Options>(
	id: string,
	options?: TOptions,
	infinite?: boolean,
	tags?: ReadonlyArray<string>,
): [QueryKey<TOptions>[0]] => {
	const params: QueryKey<TOptions>[0] = {
		_id: id,
		baseUrl: options?.baseUrl || (options?.client ?? _heyApiClient).getConfig().baseUrl,
	} as QueryKey<TOptions>[0];
	if (infinite) {
		params._infinite = infinite;
	}
	if (tags) {
		params.tags = tags;
	}
	if (options?.body) {
		params.body = options.body;
	}
	if (options?.headers) {
		params.headers = options.headers;
	}
	if (options?.path) {
		params.path = options.path;
	}
	if (options?.query) {
		params.query = options.query;
	}
	return [params];
};

export const registerQueryKey = (options?: Options<RegisterData>) => createQueryKey("register", options);

/**
 * Register a new user
 */
export const registerOptions = (options?: Options<RegisterData>) => {
	return queryOptions({
		queryFn: async ({ queryKey, signal }) => {
			const { data } = await register({
				...options,
				...queryKey[0],
				signal,
				throwOnError: true,
			});
			return data;
		},
		queryKey: registerQueryKey(options),
	});
};

/**
 * Register a new user
 */
export const registerMutation = (
	options?: Partial<Options<RegisterData>>,
): UseMutationOptions<RegisterResponse, DefaultError, Options<RegisterData>> => {
	const mutationOptions: UseMutationOptions<RegisterResponse, DefaultError, Options<RegisterData>> = {
		mutationFn: async (localOptions) => {
			const { data } = await register({
				...options,
				...localOptions,
				throwOnError: true,
			});
			return data;
		},
	};
	return mutationOptions;
};

export const loginQueryKey = (options?: Options<LoginData>) => createQueryKey("login", options);

/**
 * Login with username and password
 */
export const loginOptions = (options?: Options<LoginData>) => {
	return queryOptions({
		queryFn: async ({ queryKey, signal }) => {
			const { data } = await login({
				...options,
				...queryKey[0],
				signal,
				throwOnError: true,
			});
			return data;
		},
		queryKey: loginQueryKey(options),
	});
};

/**
 * Login with username and password
 */
export const loginMutation = (
	options?: Partial<Options<LoginData>>,
): UseMutationOptions<LoginResponse, DefaultError, Options<LoginData>> => {
	const mutationOptions: UseMutationOptions<LoginResponse, DefaultError, Options<LoginData>> = {
		mutationFn: async (localOptions) => {
			const { data } = await login({
				...options,
				...localOptions,
				throwOnError: true,
			});
			return data;
		},
	};
	return mutationOptions;
};

export const logoutQueryKey = (options?: Options<LogoutData>) => createQueryKey("logout", options);

/**
 * Logout current user
 */
export const logoutOptions = (options?: Options<LogoutData>) => {
	return queryOptions({
		queryFn: async ({ queryKey, signal }) => {
			const { data } = await logout({
				...options,
				...queryKey[0],
				signal,
				throwOnError: true,
			});
			return data;
		},
		queryKey: logoutQueryKey(options),
	});
};

/**
 * Logout current user
 */
export const logoutMutation = (
	options?: Partial<Options<LogoutData>>,
): UseMutationOptions<LogoutResponse, DefaultError, Options<LogoutData>> => {
	const mutationOptions: UseMutationOptions<LogoutResponse, DefaultError, Options<LogoutData>> = {
		mutationFn: async (localOptions) => {
			const { data } = await logout({
				...options,
				...localOptions,
				throwOnError: true,
			});
			return data;
		},
	};
	return mutationOptions;
};

export const getMeQueryKey = (options?: Options<GetMeData>) => createQueryKey("getMe", options);

/**
 * Get current authenticated user
 */
export const getMeOptions = (options?: Options<GetMeData>) => {
	return queryOptions({
		queryFn: async ({ queryKey, signal }) => {
			const { data } = await getMe({
				...options,
				...queryKey[0],
				signal,
				throwOnError: true,
			});
			return data;
		},
		queryKey: getMeQueryKey(options),
	});
};

export const getStatusQueryKey = (options?: Options<GetStatusData>) => createQueryKey("getStatus", options);

/**
 * Get authentication system status
 */
export const getStatusOptions = (options?: Options<GetStatusData>) => {
	return queryOptions({
		queryFn: async ({ queryKey, signal }) => {
			const { data } = await getStatus({
				...options,
				...queryKey[0],
				signal,
				throwOnError: true,
			});
			return data;
		},
		queryKey: getStatusQueryKey(options),
	});
};

export const changePasswordQueryKey = (options?: Options<ChangePasswordData>) =>
	createQueryKey("changePassword", options);

/**
 * Change current user password
 */
export const changePasswordOptions = (options?: Options<ChangePasswordData>) => {
	return queryOptions({
		queryFn: async ({ queryKey, signal }) => {
			const { data } = await changePassword({
				...options,
				...queryKey[0],
				signal,
				throwOnError: true,
			});
			return data;
		},
		queryKey: changePasswordQueryKey(options),
	});
};

/**
 * Change current user password
 */
export const changePasswordMutation = (
	options?: Partial<Options<ChangePasswordData>>,
): UseMutationOptions<ChangePasswordResponse, DefaultError, Options<ChangePasswordData>> => {
	const mutationOptions: UseMutationOptions<ChangePasswordResponse, DefaultError, Options<ChangePasswordData>> = {
		mutationFn: async (localOptions) => {
			const { data } = await changePassword({
				...options,
				...localOptions,
				throwOnError: true,
			});
			return data;
		},
	};
	return mutationOptions;
};

export const listVolumesQueryKey = (options?: Options<ListVolumesData>) => createQueryKey("listVolumes", options);

/**
 * List all volumes
 */
export const listVolumesOptions = (options?: Options<ListVolumesData>) => {
	return queryOptions({
		queryFn: async ({ queryKey, signal }) => {
			const { data } = await listVolumes({
				...options,
				...queryKey[0],
				signal,
				throwOnError: true,
			});
			return data;
		},
		queryKey: listVolumesQueryKey(options),
	});
};

export const createVolumeQueryKey = (options?: Options<CreateVolumeData>) => createQueryKey("createVolume", options);

/**
 * Create a new volume
 */
export const createVolumeOptions = (options?: Options<CreateVolumeData>) => {
	return queryOptions({
		queryFn: async ({ queryKey, signal }) => {
			const { data } = await createVolume({
				...options,
				...queryKey[0],
				signal,
				throwOnError: true,
			});
			return data;
		},
		queryKey: createVolumeQueryKey(options),
	});
};

/**
 * Create a new volume
 */
export const createVolumeMutation = (
	options?: Partial<Options<CreateVolumeData>>,
): UseMutationOptions<CreateVolumeResponse, DefaultError, Options<CreateVolumeData>> => {
	const mutationOptions: UseMutationOptions<CreateVolumeResponse, DefaultError, Options<CreateVolumeData>> = {
		mutationFn: async (localOptions) => {
			const { data } = await createVolume({
				...options,
				...localOptions,
				throwOnError: true,
			});
			return data;
		},
	};
	return mutationOptions;
};

export const testConnectionQueryKey = (options?: Options<TestConnectionData>) =>
	createQueryKey("testConnection", options);

/**
 * Test connection to backend
 */
export const testConnectionOptions = (options?: Options<TestConnectionData>) => {
	return queryOptions({
		queryFn: async ({ queryKey, signal }) => {
			const { data } = await testConnection({
				...options,
				...queryKey[0],
				signal,
				throwOnError: true,
			});
			return data;
		},
		queryKey: testConnectionQueryKey(options),
	});
};

/**
 * Test connection to backend
 */
export const testConnectionMutation = (
	options?: Partial<Options<TestConnectionData>>,
): UseMutationOptions<TestConnectionResponse, DefaultError, Options<TestConnectionData>> => {
	const mutationOptions: UseMutationOptions<TestConnectionResponse, DefaultError, Options<TestConnectionData>> = {
		mutationFn: async (localOptions) => {
			const { data } = await testConnection({
				...options,
				...localOptions,
				throwOnError: true,
			});
			return data;
		},
	};
	return mutationOptions;
};

/**
 * Delete a volume
 */
export const deleteVolumeMutation = (
	options?: Partial<Options<DeleteVolumeData>>,
): UseMutationOptions<DeleteVolumeResponse, DefaultError, Options<DeleteVolumeData>> => {
	const mutationOptions: UseMutationOptions<DeleteVolumeResponse, DefaultError, Options<DeleteVolumeData>> = {
		mutationFn: async (localOptions) => {
			const { data } = await deleteVolume({
				...options,
				...localOptions,
				throwOnError: true,
			});
			return data;
		},
	};
	return mutationOptions;
};

export const getVolumeQueryKey = (options: Options<GetVolumeData>) => createQueryKey("getVolume", options);

/**
 * Get a volume by name
 */
export const getVolumeOptions = (options: Options<GetVolumeData>) => {
	return queryOptions({
		queryFn: async ({ queryKey, signal }) => {
			const { data } = await getVolume({
				...options,
				...queryKey[0],
				signal,
				throwOnError: true,
			});
			return data;
		},
		queryKey: getVolumeQueryKey(options),
	});
};

/**
 * Update a volume's configuration
 */
export const updateVolumeMutation = (
	options?: Partial<Options<UpdateVolumeData>>,
): UseMutationOptions<UpdateVolumeResponse, DefaultError, Options<UpdateVolumeData>> => {
	const mutationOptions: UseMutationOptions<UpdateVolumeResponse, DefaultError, Options<UpdateVolumeData>> = {
		mutationFn: async (localOptions) => {
			const { data } = await updateVolume({
				...options,
				...localOptions,
				throwOnError: true,
			});
			return data;
		},
	};
	return mutationOptions;
};

export const getContainersUsingVolumeQueryKey = (options: Options<GetContainersUsingVolumeData>) =>
	createQueryKey("getContainersUsingVolume", options);

/**
 * Get containers using a volume by name
 */
export const getContainersUsingVolumeOptions = (options: Options<GetContainersUsingVolumeData>) => {
	return queryOptions({
		queryFn: async ({ queryKey, signal }) => {
			const { data } = await getContainersUsingVolume({
				...options,
				...queryKey[0],
				signal,
				throwOnError: true,
			});
			return data;
		},
		queryKey: getContainersUsingVolumeQueryKey(options),
	});
};

export const mountVolumeQueryKey = (options: Options<MountVolumeData>) => createQueryKey("mountVolume", options);

/**
 * Mount a volume
 */
export const mountVolumeOptions = (options: Options<MountVolumeData>) => {
	return queryOptions({
		queryFn: async ({ queryKey, signal }) => {
			const { data } = await mountVolume({
				...options,
				...queryKey[0],
				signal,
				throwOnError: true,
			});
			return data;
		},
		queryKey: mountVolumeQueryKey(options),
	});
};

/**
 * Mount a volume
 */
export const mountVolumeMutation = (
	options?: Partial<Options<MountVolumeData>>,
): UseMutationOptions<MountVolumeResponse, DefaultError, Options<MountVolumeData>> => {
	const mutationOptions: UseMutationOptions<MountVolumeResponse, DefaultError, Options<MountVolumeData>> = {
		mutationFn: async (localOptions) => {
			const { data } = await mountVolume({
				...options,
				...localOptions,
				throwOnError: true,
			});
			return data;
		},
	};
	return mutationOptions;
};

export const unmountVolumeQueryKey = (options: Options<UnmountVolumeData>) => createQueryKey("unmountVolume", options);

/**
 * Unmount a volume
 */
export const unmountVolumeOptions = (options: Options<UnmountVolumeData>) => {
	return queryOptions({
		queryFn: async ({ queryKey, signal }) => {
			const { data } = await unmountVolume({
				...options,
				...queryKey[0],
				signal,
				throwOnError: true,
			});
			return data;
		},
		queryKey: unmountVolumeQueryKey(options),
	});
};

/**
 * Unmount a volume
 */
export const unmountVolumeMutation = (
	options?: Partial<Options<UnmountVolumeData>>,
): UseMutationOptions<UnmountVolumeResponse, DefaultError, Options<UnmountVolumeData>> => {
	const mutationOptions: UseMutationOptions<UnmountVolumeResponse, DefaultError, Options<UnmountVolumeData>> = {
		mutationFn: async (localOptions) => {
			const { data } = await unmountVolume({
				...options,
				...localOptions,
				throwOnError: true,
			});
			return data;
		},
	};
	return mutationOptions;
};

export const healthCheckVolumeQueryKey = (options: Options<HealthCheckVolumeData>) =>
	createQueryKey("healthCheckVolume", options);

/**
 * Perform a health check on a volume
 */
export const healthCheckVolumeOptions = (options: Options<HealthCheckVolumeData>) => {
	return queryOptions({
		queryFn: async ({ queryKey, signal }) => {
			const { data } = await healthCheckVolume({
				...options,
				...queryKey[0],
				signal,
				throwOnError: true,
			});
			return data;
		},
		queryKey: healthCheckVolumeQueryKey(options),
	});
};

/**
 * Perform a health check on a volume
 */
export const healthCheckVolumeMutation = (
	options?: Partial<Options<HealthCheckVolumeData>>,
): UseMutationOptions<HealthCheckVolumeResponse, DefaultError, Options<HealthCheckVolumeData>> => {
	const mutationOptions: UseMutationOptions<HealthCheckVolumeResponse, DefaultError, Options<HealthCheckVolumeData>> = {
		mutationFn: async (localOptions) => {
			const { data } = await healthCheckVolume({
				...options,
				...localOptions,
				throwOnError: true,
			});
			return data;
		},
	};
	return mutationOptions;
};

export const listFilesQueryKey = (options: Options<ListFilesData>) => createQueryKey("listFiles", options);

/**
 * List files in a volume directory
 */
export const listFilesOptions = (options: Options<ListFilesData>) => {
	return queryOptions({
		queryFn: async ({ queryKey, signal }) => {
			const { data } = await listFiles({
				...options,
				...queryKey[0],
				signal,
				throwOnError: true,
			});
			return data;
		},
		queryKey: listFilesQueryKey(options),
	});
};

export const browseFilesystemQueryKey = (options?: Options<BrowseFilesystemData>) =>
	createQueryKey("browseFilesystem", options);

/**
 * Browse directories on the host filesystem
 */
export const browseFilesystemOptions = (options?: Options<BrowseFilesystemData>) => {
	return queryOptions({
		queryFn: async ({ queryKey, signal }) => {
			const { data } = await browseFilesystem({
				...options,
				...queryKey[0],
				signal,
				throwOnError: true,
			});
			return data;
		},
		queryKey: browseFilesystemQueryKey(options),
	});
};

export const listRepositoriesQueryKey = (options?: Options<ListRepositoriesData>) =>
	createQueryKey("listRepositories", options);

/**
 * List all repositories
 */
export const listRepositoriesOptions = (options?: Options<ListRepositoriesData>) => {
	return queryOptions({
		queryFn: async ({ queryKey, signal }) => {
			const { data } = await listRepositories({
				...options,
				...queryKey[0],
				signal,
				throwOnError: true,
			});
			return data;
		},
		queryKey: listRepositoriesQueryKey(options),
	});
};

export const createRepositoryQueryKey = (options?: Options<CreateRepositoryData>) =>
	createQueryKey("createRepository", options);

/**
 * Create a new restic repository
 */
export const createRepositoryOptions = (options?: Options<CreateRepositoryData>) => {
	return queryOptions({
		queryFn: async ({ queryKey, signal }) => {
			const { data } = await createRepository({
				...options,
				...queryKey[0],
				signal,
				throwOnError: true,
			});
			return data;
		},
		queryKey: createRepositoryQueryKey(options),
	});
};

/**
 * Create a new restic repository
 */
export const createRepositoryMutation = (
	options?: Partial<Options<CreateRepositoryData>>,
): UseMutationOptions<CreateRepositoryResponse, DefaultError, Options<CreateRepositoryData>> => {
	const mutationOptions: UseMutationOptions<CreateRepositoryResponse, DefaultError, Options<CreateRepositoryData>> = {
		mutationFn: async (localOptions) => {
			const { data } = await createRepository({
				...options,
				...localOptions,
				throwOnError: true,
			});
			return data;
		},
	};
	return mutationOptions;
};

export const listRcloneRemotesQueryKey = (options?: Options<ListRcloneRemotesData>) =>
	createQueryKey("listRcloneRemotes", options);

/**
 * List all configured rclone remotes on the host system
 */
export const listRcloneRemotesOptions = (options?: Options<ListRcloneRemotesData>) => {
	return queryOptions({
		queryFn: async ({ queryKey, signal }) => {
			const { data } = await listRcloneRemotes({
				...options,
				...queryKey[0],
				signal,
				throwOnError: true,
			});
			return data;
		},
		queryKey: listRcloneRemotesQueryKey(options),
	});
};

/**
 * Delete a repository
 */
export const deleteRepositoryMutation = (
	options?: Partial<Options<DeleteRepositoryData>>,
): UseMutationOptions<DeleteRepositoryResponse, DefaultError, Options<DeleteRepositoryData>> => {
	const mutationOptions: UseMutationOptions<DeleteRepositoryResponse, DefaultError, Options<DeleteRepositoryData>> = {
		mutationFn: async (localOptions) => {
			const { data } = await deleteRepository({
				...options,
				...localOptions,
				throwOnError: true,
			});
			return data;
		},
	};
	return mutationOptions;
};

export const getRepositoryQueryKey = (options: Options<GetRepositoryData>) => createQueryKey("getRepository", options);

/**
 * Get a single repository by name
 */
export const getRepositoryOptions = (options: Options<GetRepositoryData>) => {
	return queryOptions({
		queryFn: async ({ queryKey, signal }) => {
			const { data } = await getRepository({
				...options,
				...queryKey[0],
				signal,
				throwOnError: true,
			});
			return data;
		},
		queryKey: getRepositoryQueryKey(options),
	});
};

export const listSnapshotsQueryKey = (options: Options<ListSnapshotsData>) => createQueryKey("listSnapshots", options);

/**
 * List all snapshots in a repository
 */
export const listSnapshotsOptions = (options: Options<ListSnapshotsData>) => {
	return queryOptions({
		queryFn: async ({ queryKey, signal }) => {
			const { data } = await listSnapshots({
				...options,
				...queryKey[0],
				signal,
				throwOnError: true,
			});
			return data;
		},
		queryKey: listSnapshotsQueryKey(options),
	});
};

export const getSnapshotDetailsQueryKey = (options: Options<GetSnapshotDetailsData>) =>
	createQueryKey("getSnapshotDetails", options);

/**
 * Get details of a specific snapshot
 */
export const getSnapshotDetailsOptions = (options: Options<GetSnapshotDetailsData>) => {
	return queryOptions({
		queryFn: async ({ queryKey, signal }) => {
			const { data } = await getSnapshotDetails({
				...options,
				...queryKey[0],
				signal,
				throwOnError: true,
			});
			return data;
		},
		queryKey: getSnapshotDetailsQueryKey(options),
	});
};

export const listSnapshotFilesQueryKey = (options: Options<ListSnapshotFilesData>) =>
	createQueryKey("listSnapshotFiles", options);

/**
 * List files and directories in a snapshot
 */
export const listSnapshotFilesOptions = (options: Options<ListSnapshotFilesData>) => {
	return queryOptions({
		queryFn: async ({ queryKey, signal }) => {
			const { data } = await listSnapshotFiles({
				...options,
				...queryKey[0],
				signal,
				throwOnError: true,
			});
			return data;
		},
		queryKey: listSnapshotFilesQueryKey(options),
	});
};

export const restoreSnapshotQueryKey = (options: Options<RestoreSnapshotData>) =>
	createQueryKey("restoreSnapshot", options);

/**
 * Restore a snapshot to a target path on the filesystem
 */
export const restoreSnapshotOptions = (options: Options<RestoreSnapshotData>) => {
	return queryOptions({
		queryFn: async ({ queryKey, signal }) => {
			const { data } = await restoreSnapshot({
				...options,
				...queryKey[0],
				signal,
				throwOnError: true,
			});
			return data;
		},
		queryKey: restoreSnapshotQueryKey(options),
	});
};

/**
 * Restore a snapshot to a target path on the filesystem
 */
export const restoreSnapshotMutation = (
	options?: Partial<Options<RestoreSnapshotData>>,
): UseMutationOptions<RestoreSnapshotResponse, DefaultError, Options<RestoreSnapshotData>> => {
	const mutationOptions: UseMutationOptions<RestoreSnapshotResponse, DefaultError, Options<RestoreSnapshotData>> = {
		mutationFn: async (localOptions) => {
			const { data } = await restoreSnapshot({
				...options,
				...localOptions,
				throwOnError: true,
			});
			return data;
		},
	};
	return mutationOptions;
};

export const doctorRepositoryQueryKey = (options: Options<DoctorRepositoryData>) =>
	createQueryKey("doctorRepository", options);

/**
 * Run doctor operations on a repository to fix common issues (unlock, check, repair index). Use this when the repository is locked or has errors.
 */
export const doctorRepositoryOptions = (options: Options<DoctorRepositoryData>) => {
	return queryOptions({
		queryFn: async ({ queryKey, signal }) => {
			const { data } = await doctorRepository({
				...options,
				...queryKey[0],
				signal,
				throwOnError: true,
			});
			return data;
		},
		queryKey: doctorRepositoryQueryKey(options),
	});
};

/**
 * Run doctor operations on a repository to fix common issues (unlock, check, repair index). Use this when the repository is locked or has errors.
 */
export const doctorRepositoryMutation = (
	options?: Partial<Options<DoctorRepositoryData>>,
): UseMutationOptions<DoctorRepositoryResponse, DefaultError, Options<DoctorRepositoryData>> => {
	const mutationOptions: UseMutationOptions<DoctorRepositoryResponse, DefaultError, Options<DoctorRepositoryData>> = {
		mutationFn: async (localOptions) => {
			const { data } = await doctorRepository({
				...options,
				...localOptions,
				throwOnError: true,
			});
			return data;
		},
	};
	return mutationOptions;
};

export const listBackupSchedulesQueryKey = (options?: Options<ListBackupSchedulesData>) =>
	createQueryKey("listBackupSchedules", options);

/**
 * List all backup schedules
 */
export const listBackupSchedulesOptions = (options?: Options<ListBackupSchedulesData>) => {
	return queryOptions({
		queryFn: async ({ queryKey, signal }) => {
			const { data } = await listBackupSchedules({
				...options,
				...queryKey[0],
				signal,
				throwOnError: true,
			});
			return data;
		},
		queryKey: listBackupSchedulesQueryKey(options),
	});
};

export const createBackupScheduleQueryKey = (options?: Options<CreateBackupScheduleData>) =>
	createQueryKey("createBackupSchedule", options);

/**
 * Create a new backup schedule for a volume
 */
export const createBackupScheduleOptions = (options?: Options<CreateBackupScheduleData>) => {
	return queryOptions({
		queryFn: async ({ queryKey, signal }) => {
			const { data } = await createBackupSchedule({
				...options,
				...queryKey[0],
				signal,
				throwOnError: true,
			});
			return data;
		},
		queryKey: createBackupScheduleQueryKey(options),
	});
};

/**
 * Create a new backup schedule for a volume
 */
export const createBackupScheduleMutation = (
	options?: Partial<Options<CreateBackupScheduleData>>,
): UseMutationOptions<CreateBackupScheduleResponse, DefaultError, Options<CreateBackupScheduleData>> => {
	const mutationOptions: UseMutationOptions<
		CreateBackupScheduleResponse,
		DefaultError,
		Options<CreateBackupScheduleData>
	> = {
		mutationFn: async (localOptions) => {
			const { data } = await createBackupSchedule({
				...options,
				...localOptions,
				throwOnError: true,
			});
			return data;
		},
	};
	return mutationOptions;
};

/**
 * Delete a backup schedule
 */
export const deleteBackupScheduleMutation = (
	options?: Partial<Options<DeleteBackupScheduleData>>,
): UseMutationOptions<DeleteBackupScheduleResponse, DefaultError, Options<DeleteBackupScheduleData>> => {
	const mutationOptions: UseMutationOptions<
		DeleteBackupScheduleResponse,
		DefaultError,
		Options<DeleteBackupScheduleData>
	> = {
		mutationFn: async (localOptions) => {
			const { data } = await deleteBackupSchedule({
				...options,
				...localOptions,
				throwOnError: true,
			});
			return data;
		},
	};
	return mutationOptions;
};

export const getBackupScheduleQueryKey = (options: Options<GetBackupScheduleData>) =>
	createQueryKey("getBackupSchedule", options);

/**
 * Get a backup schedule by ID
 */
export const getBackupScheduleOptions = (options: Options<GetBackupScheduleData>) => {
	return queryOptions({
		queryFn: async ({ queryKey, signal }) => {
			const { data } = await getBackupSchedule({
				...options,
				...queryKey[0],
				signal,
				throwOnError: true,
			});
			return data;
		},
		queryKey: getBackupScheduleQueryKey(options),
	});
};

/**
 * Update a backup schedule
 */
export const updateBackupScheduleMutation = (
	options?: Partial<Options<UpdateBackupScheduleData>>,
): UseMutationOptions<UpdateBackupScheduleResponse, DefaultError, Options<UpdateBackupScheduleData>> => {
	const mutationOptions: UseMutationOptions<
		UpdateBackupScheduleResponse,
		DefaultError,
		Options<UpdateBackupScheduleData>
	> = {
		mutationFn: async (localOptions) => {
			const { data } = await updateBackupSchedule({
				...options,
				...localOptions,
				throwOnError: true,
			});
			return data;
		},
	};
	return mutationOptions;
};

export const getBackupScheduleForVolumeQueryKey = (options: Options<GetBackupScheduleForVolumeData>) =>
	createQueryKey("getBackupScheduleForVolume", options);

/**
 * Get a backup schedule for a specific volume
 */
export const getBackupScheduleForVolumeOptions = (options: Options<GetBackupScheduleForVolumeData>) => {
	return queryOptions({
		queryFn: async ({ queryKey, signal }) => {
			const { data } = await getBackupScheduleForVolume({
				...options,
				...queryKey[0],
				signal,
				throwOnError: true,
			});
			return data;
		},
		queryKey: getBackupScheduleForVolumeQueryKey(options),
	});
};

export const runBackupNowQueryKey = (options: Options<RunBackupNowData>) => createQueryKey("runBackupNow", options);

/**
 * Trigger a backup immediately for a schedule
 */
export const runBackupNowOptions = (options: Options<RunBackupNowData>) => {
	return queryOptions({
		queryFn: async ({ queryKey, signal }) => {
			const { data } = await runBackupNow({
				...options,
				...queryKey[0],
				signal,
				throwOnError: true,
			});
			return data;
		},
		queryKey: runBackupNowQueryKey(options),
	});
};

/**
 * Trigger a backup immediately for a schedule
 */
export const runBackupNowMutation = (
	options?: Partial<Options<RunBackupNowData>>,
): UseMutationOptions<RunBackupNowResponse, DefaultError, Options<RunBackupNowData>> => {
	const mutationOptions: UseMutationOptions<RunBackupNowResponse, DefaultError, Options<RunBackupNowData>> = {
		mutationFn: async (localOptions) => {
			const { data } = await runBackupNow({
				...options,
				...localOptions,
				throwOnError: true,
			});
			return data;
		},
	};
	return mutationOptions;
};

export const stopBackupQueryKey = (options: Options<StopBackupData>) => createQueryKey("stopBackup", options);

/**
 * Stop a backup that is currently in progress
 */
export const stopBackupOptions = (options: Options<StopBackupData>) => {
	return queryOptions({
		queryFn: async ({ queryKey, signal }) => {
			const { data } = await stopBackup({
				...options,
				...queryKey[0],
				signal,
				throwOnError: true,
			});
			return data;
		},
		queryKey: stopBackupQueryKey(options),
	});
};

/**
 * Stop a backup that is currently in progress
 */
export const stopBackupMutation = (
	options?: Partial<Options<StopBackupData>>,
): UseMutationOptions<StopBackupResponse, DefaultError, Options<StopBackupData>> => {
	const mutationOptions: UseMutationOptions<StopBackupResponse, DefaultError, Options<StopBackupData>> = {
		mutationFn: async (localOptions) => {
			const { data } = await stopBackup({
				...options,
				...localOptions,
				throwOnError: true,
			});
			return data;
		},
	};
	return mutationOptions;
};

export const getSystemInfoQueryKey = (options?: Options<GetSystemInfoData>) => createQueryKey("getSystemInfo", options);

/**
 * Get system information including available capabilities
 */
export const getSystemInfoOptions = (options?: Options<GetSystemInfoData>) => {
	return queryOptions({
		queryFn: async ({ queryKey, signal }) => {
			const { data } = await getSystemInfo({
				...options,
				...queryKey[0],
				signal,
				throwOnError: true,
			});
			return data;
		},
		queryKey: getSystemInfoQueryKey(options),
	});
};

export const downloadResticPasswordQueryKey = (options?: Options<DownloadResticPasswordData>) =>
	createQueryKey("downloadResticPassword", options);

/**
 * Download the Restic password file for backup recovery. Requires password re-authentication.
 */
export const downloadResticPasswordOptions = (options?: Options<DownloadResticPasswordData>) => {
	return queryOptions({
		queryFn: async ({ queryKey, signal }) => {
			const { data } = await downloadResticPassword({
				...options,
				...queryKey[0],
				signal,
				throwOnError: true,
			});
			return data;
		},
		queryKey: downloadResticPasswordQueryKey(options),
	});
};

/**
 * Download the Restic password file for backup recovery. Requires password re-authentication.
 */
export const downloadResticPasswordMutation = (
	options?: Partial<Options<DownloadResticPasswordData>>,
): UseMutationOptions<DownloadResticPasswordResponse, DefaultError, Options<DownloadResticPasswordData>> => {
	const mutationOptions: UseMutationOptions<
		DownloadResticPasswordResponse,
		DefaultError,
		Options<DownloadResticPasswordData>
	> = {
		mutationFn: async (localOptions) => {
			const { data } = await downloadResticPassword({
				...options,
				...localOptions,
				throwOnError: true,
			});
			return data;
		},
	};
	return mutationOptions;
};
