/*
 * Copyright (C) 2019 Robert Bosch GmbH Copyright (C) 2019 Robert Bosch Manufacturing Solutions GmbH, Germany. All rights reserved.
 */

import { DataSource } from '@angular/cdk/table';
import { Observable } from 'rxjs';

/**
 * A wrapper model for input data to be displayed as columns. Input must be provided as a linked list of items. The list
 * will be transformed into columns according to each item's depth in the list.
 *
 * Example: The linked list
 * A
 * +-- A1
 * +-- A2
 * B
 * +-- B1
 *     +-- B11
 * will be transformed into the column model
 * `Column 1: A, B, column 2: A1, A2, B1, column 3: B11`
 */
export interface BciColumnBrowserModel<TInput = any> {
  label: string;
  model: TInput;
  children: BciColumnBrowserModel[];
}

/** Model of the selection event of a single column item. */
export interface SelectionChange {
  /** The selected item's column index. */
  columnIndex: number;

  /** Whether the item has been selected or deselected. */
  selected: boolean;

  /** The selected item. */
  item: BciColumnBrowserModel;

  /**
   * The selected path through the visible columns including the selected item if {@link SelectionChange#selected}
   * is `true`.
   */
  selectedPath: any[];
}

/** A filter expression that is assigned to a column. */
export interface ColumnFilter {
  /** Active column index that is part of {@link ColumnFilter#filter the filters}. */
  columnIndex: number;

  /** Filter for each column. */
  filter: string[];
}

/** A view model of a single column. A column has a title and consists of multiple {@link ColumnItem items}. */
export class Column {
  /**
   * @param title
   * @param items
   */
  constructor(public title: string, public items: ColumnItem[]) {}
}

/** A view model of a column's item. */
export class ColumnItem {
  /**
   * @param item
   * @param parentItem
   * @param label
   * @param selected
   * @param visible
   * @param hasChildren
   */
  constructor(
    public item: BciColumnBrowserModel,
    public parentItem: ColumnItem,
    public label: string,
    public selected: boolean,
    public visible: boolean = false,
    public hasChildren: boolean = false
  ) {}
}

export type ColumnsDataSource =
  | DataSource<BciColumnBrowserModel>
  | Observable<BciColumnBrowserModel[]>
  | BciColumnBrowserModel[];
