import { useMutation, useQueryClient } from '@tanstack/react-query';
import { partnerCenterApi } from '../apis';
import { centerKeys } from '../keys';
import type { PartnerCenter, PartnerCenterInput } from '../types';

/** Create a partner center (inactive until verified). Invalidate the center lists. */
export function useCreatePartnerCenter() {
  const queryClient = useQueryClient();
  return useMutation<PartnerCenter, unknown, PartnerCenterInput>({
    mutationFn: (input) => partnerCenterApi.createCenter(input),
    onSuccess: () => {
      queryClient.invalidateQueries({ queryKey: centerKeys.lists() });
    },
  });
}
