import {
  CollectionState,
  ComputedQuery,
  Filter,
  FiltersMap,
} from '@wix/bex-core';
import { NestedOptimisticActionsState } from './createNestedOptimisticActions';

export interface NestedCollectionLevelDescriptor<T, F extends FiltersMap> {
  readonly depth: number;
  /**
   * A function that accepts the item of the current level and returns the key of the parent item, for example: `(item) => item.parentId`.
   */
  readonly parentKey: (item: T) => string | null | undefined;
  readonly setParent?: (
    item: T,
    parentId: string | undefined,
    additionalInfo: {
      parentItem?: {};
    },
  ) => T;
  /**
   * A function that creates a collection for the current level (using [useCreateCollection](./?path=/story/common-hooks--usecreatecollection) hook), and returns the collection state and a reference to a filter object within this collection that filters the collection by the parent key.
   * @overrideType (state) => { collection: [CollectionState](./?path=/story/common-state--collectionstate); parentFilter?: [Filter<string[]>](./?path=/story/features-filter-factories--stringsarrayfilter); }
   */
  readonly createCollection: (params?: NestedOptimisticActionsState<T, F>) => {
    collection: CollectionState<T, F>;
    parentFilter?: Filter<string[]>;
  };
  readonly fetchAllThreshold?: number;
  readonly isSameEntityAsOtherLevels?: boolean;
  /**
   * A [predicate](./?path=/story/features-actions-updates--useoptimisticactions) function to pass to the internal [OptimisticActions](/?path=/story/features-actions-updates--collectionoptimisticactions) created by NestedTable
   */
  readonly optimisticActionsPredicate?: (
    query: ComputedQuery<F>,
  ) => (item: T) => boolean;
}
