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

export class Filter<Entity, Term> {
  public label = () => this.prefix + (this.term === undefined ? '' : this.term);
  public clear = () => (this.term = undefined);

  constructor(public prefix: string, public term: Term, public keep: (entity: Entity, term: any) => boolean) {}
}

export class ListFilter<Entity, Term> extends Filter<Entity, Term[]> {
  public label = () => this.prefix + (this.term === undefined ? '' : this.term.join(', '));
}

export class DateFilter<Entity> extends Filter<Entity, Date> {
  public label = () => this.prefix + this.term.toLocaleDateString();
}
