import { CollectionState, FiltersMap } from '@wix/bex-core';
import { NestedTableNodeStateOptimisticActionsPublicAPI } from './NestedTableNodeStateOptimisticActions';

export interface NestedTableNodeStatePublicAPI<
  C extends string,
  T,
  F extends FiltersMap,
> {
  /**
   * Get the node this node is a child of
   * @overrideType () => [NestedTableNodeState](./?path=/story/base-components-collections-nestedtable--nestedtablenodestate) | `undefined`
   */
  getParent<TD, FD extends FiltersMap>(): NestedTableNodeStatePublicAPI<
    C,
    TD,
    FD
  > | null;
  /**
   * The collection of the node
   * @overrideType [CollectionState](./?path=/story/common-state--collectionstate)
   */
  readonly children?: CollectionState<T, F>;

  /**
   * The optimistic actions of the node, affects items both in nested & flat mode
   * @overrideType [NestedTableOptimisticActions](./?path=/story/base-components-collections-nestedtable--nestedtableoptimisticactions)
   */
  readonly optimisticActions?: NestedTableNodeStateOptimisticActionsPublicAPI<T>;

  /**
   * The "parent" item of this node
   * @overrideType <T>() => T | null
   */
  getData: <TD>() => TD | null;

  /**
   * Toggle the expand/collapse state of the node
   */
  toggleExpand: () => void;

  /**
   * Whether the node is expanded
   */
  readonly expanded: boolean;

  /**
   * The depth of the node in the tree
   */
  readonly depth: number;

  /**
   * Get all the nodes that are descendants of this node from all levels
   * @overrideType () => [NestedTableNodeState](./?path=/story/base-components-collections-nestedtable--nestedtablenodestate)[]
   */
  getDescendants<TD, FD extends FiltersMap>(): NestedTableNodeStatePublicAPI<
    C,
    TD,
    FD
  >[];
}
