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

/** Update a partner center (replace semantics; IBAN write-then-masked). Invalidate list + detail. */
export function useUpdatePartnerCenter(id: number) {
  const queryClient = useQueryClient();
  return useMutation<PartnerCenter, unknown, PartnerCenterInput>({
    mutationFn: (input) => partnerCenterApi.updateCenter(id, input),
    onSuccess: () => {
      queryClient.invalidateQueries({ queryKey: centerKeys.lists() });
      queryClient.invalidateQueries({ queryKey: centerKeys.detail(id) });
    },
  });
}
