// src/services/<service-name>.hooks.ts
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
import { <serviceName>Service } from './<service-name>';

// Query keys factory
export const <serviceName>Keys = {
  all: () => ['<service-name>'] as const,
  contacts: () => [...<serviceName>Keys.all(), 'contacts'] as const,
};

// Query hooks
export const useGetContacts = () => {
  const { data, ...query } = useQuery({
    queryKey: <serviceName>Keys.contacts(),
    queryFn: <serviceName>Service.getContacts,
  });

  return { contacts: data ?? [], ...query };
};

// Mutation hooks
export const useCreateContactMutation = () => {
  const queryClient = useQueryClient();

  return useMutation({
    mutationFn: <serviceName>Service.createContact,
    onSuccess: () => {
      queryClient.invalidateQueries({ queryKey: <serviceName>Keys.contacts() });
    },
  });
};
