import pick from 'lodash/pick';
import {BaseModel} from './base.model';
import {IdModel} from './id.model';

export class UserModel extends BaseModel{
  _id: IdModel = null;
  name = '';
  origName = '';
  email = '';
  level = '';
  location = '';
  devices = [''];
  models = [''];
  status = 'new';
  edit = false;

  deserialize(input: any): this {
    Object.assign(this, input);
    this.origName = this.name;
    return this;
  }

  sendFormat(mode = 'user') {
    const keys = ['name', 'email', 'location', 'devices'];
    if (mode === 'admin') {
      keys.push('level');
      keys.push('models');
      this.devices = this.devices.filter(e => e);
      this.models = this.models.filter(e => e);
    }
    return pick(this, keys);
  }
}
