import {
  CollectionState,
  FiltersMap,
  fqdnToString,
  isFqdnValid,
} from '@wix/bex-core';
import { LoadingRowState } from '../components/LoadingRow/LoadingRowState';

export type AiAssistant = {
  useAiAssistant: <T, F extends FiltersMap>({
    collection,
    loadingRowState,
  }: {
    collection: CollectionState<T, F>;
    loadingRowState: LoadingRowState;
  }) => void;
};

export function createWixPatternsCreationEventName<T, F extends FiltersMap>(
  collection: CollectionState<T, F>,
) {
  if (!collection.fqdn || (collection.fqdn && !isFqdnValid(collection.fqdn))) {
    throw new Error(
      'FQDN is invalid. Please provide a valid FQDN in the collection hook state (use<YourComponentName>Collection)',
    );
  }
  return `ITEM_CREATED_${fqdnToString(collection.fqdn)}`;
}
