import { useQueryClient } from '@tanstack/react-query'
import { useAuthStore } from '@/zustand/authStore'
import { resetPassword, ResetPasswordRequestModel } from '@/lib/api/auth/reset-password';

export const useResetPassword = () =>
{
    const queryClient = useQueryClient()

    const run = (model: ResetPasswordRequestModel) =>
        queryClient.fetchQuery({
            queryKey: ['resetPassword', model],
            queryFn: () => resetPassword(model),
        }).then(() => {
            useAuthStore.getState().logout();
        }).catch((ex) => {
            throw ex;
        })

    return { run }
}
