import {CompositeFilterDescriptor, GroupDescriptor, SortDescriptor} from '@progress/kendo-data-query';
import {DataStateChangeEvent} from '@progress/kendo-angular-grid';


export class GridStateModel implements  DataStateChangeEvent {
  /**
   * The number of records to skip.
   */
  skip: number;
  /**
   * The number of records to take.
   */
  take: number;
  /**
   * The sort descriptors by which the data is sorted.
   */
  sort?: Array<SortDescriptor>;
  /**
   * The group descriptors by which the data is grouped.
   */
  group?: Array<GroupDescriptor>;
  /**
   * The filter descriptor by which the data is filtered.
   */
  filter?: CompositeFilterDescriptor;

  public constructor(payload?: Partial<GridStateModel>) {
    if ( ! payload ) payload = {};
    this.skip = payload.skip || 0;
    this.take = payload.take || 0;
    this.sort = payload.sort || [];
    this.group = payload.group || [];
    this.filter = payload.filter || { logic: 'and', filters: []  };
  }
}
