import { UserRepository } from '@amityco/ts-sdk-react-native';
import { useMutation, useQuery } from '@tanstack/react-query';
import { useToast } from '../../../core/stores/slices/toastSlice';
import { TOAST } from '../../../core/constants';
export const useUserFlaggedByMeQuery = ({
  userId,
  enabled
}) => {
  const {
    showToast
  } = useToast();
  const {
    data: isFlaggedByMe,
    isLoading,
    refetch
  } = useQuery({
    queryKey: ['UserRepository', 'isUserFlaggedByMe', userId],
    queryFn: () => UserRepository.isUserFlaggedByMe(userId),
    enabled: enabled && !!userId
  });
  const {
    mutate: flagUserMutate
  } = useMutation({
    mutationFn: UserRepository.flagUser
  });
  const {
    mutate: unflagUserMutate
  } = useMutation({
    mutationFn: UserRepository.unflagUser
  });
  const reportUser = targetUserId => {
    flagUserMutate(targetUserId, {
      onSuccess: () => {
        refetch();
        showToast({
          type: 'success',
          message: TOAST.USER.REPORT.SUCCESS
        });
      },
      onError: () => showToast({
        type: 'informative',
        message: TOAST.USER.REPORT.FAILED
      })
    });
  };
  const unreportUser = targetUserId => {
    unflagUserMutate(targetUserId, {
      onSuccess: () => {
        refetch();
        showToast({
          type: 'success',
          message: TOAST.USER.UNREPORT.SUCCESS
        });
      },
      onError: () => showToast({
        type: 'informative',
        message: TOAST.USER.UNREPORT.FAILED
      })
    });
  };
  return {
    isLoading,
    isFlaggedByMe,
    reportUser,
    unreportUser
  };
};
//# sourceMappingURL=useFlagUserQuery.js.map