import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";

import { getUserSettings, updateUserSettings } from "../../../contracts/userSettings";

export const useUserSettings = () => {
	const queryClient = useQueryClient();

	const { data: settings, isLoading, error } = useQuery({
		queryKey: ["userSettings"],
		queryFn: getUserSettings,
	});

	const { mutateAsync: updateSettings, isPending: isUpdating } = useMutation({
		mutationFn: updateUserSettings,
		onSuccess: () => {
			queryClient.invalidateQueries({ queryKey: ["userSettings"] });
		},
	});

	return {
		settings,
		isLoading,
		error,
		updateSettings,
		isUpdating,
	};
}; 