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 = [''];
  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');
    }
    return pick(this, keys);
  }
}
