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

export class User {
  constructor(
    public id?: string,
    public name?: string,
    public role?: string,
    public department?: string,
    public email?: string,
    public entryDate?: Date,
    public selected?: boolean
  ) {}

  compare(user: User, attribute: string): number {
    let value = 0;
    switch (attribute) {
      case 'id':
        if (+this.id > +user.id) {
          value = 1;
        }
        if (+this.id < +user.id) {
          value = -1;
        }
        break;
      case 'name':
        value = this.name.localeCompare(user.name);
        break;
      case 'role':
        value = this.role.localeCompare(user.role);
        break;
      case 'department':
        value = this.department.localeCompare(user.department);
        break;
      case 'email':
        value = this.email.localeCompare(user.email);
        break;
      case 'entryDate':
        value = this.entryDate.getTime() - user.entryDate.getTime();
        break;
    }

    return value;
  }
}
