/**
 * React Query hooks for managing business OAuth credentials
 */

import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
import { getBusinessOAuthCredentials, updateBusinessOAuthCredentials } from '../api/business';
import { BusinessOAuthCredentials } from '../types';

/**
 * Fetch business OAuth credentials
 */
export const useBusinessOAuthCredentials = () => {
  return useQuery({
    queryKey: ['businessOAuthCredentials'],
    queryFn: getBusinessOAuthCredentials,
  });
};

/**
 * Update business OAuth credentials
 */
export const useUpdateBusinessOAuthCredentials = () => {
  const queryClient = useQueryClient();

  return useMutation({
    mutationFn: (credentials: Partial<BusinessOAuthCredentials>) =>
      updateBusinessOAuthCredentials(credentials),
    onSuccess: (data) => {
      queryClient.setQueryData(['businessOAuthCredentials'], data);
    },
  });
};
