import {PeopleModel} from './people.model';
import {UserExtraModel} from './user-extra.model';

export class ApiV1LoginResponse {

  public login: boolean;
  public machineId: string;
  public session: string;
  public sessionExpire: number; // unix timestamp
  public role: string;
  public User: PeopleModel;
  public UserExtra?: UserExtraModel; // extra user information

  constructor(payload: Partial<ApiV1LoginResponse>) {
    this.login = payload.login || false;
    this.machineId = payload.machineId || '';
    this.session = payload.session || '' ;
    this.sessionExpire = payload.sessionExpire || new Date().getTime();
    this.role = payload.role || '';
    this.User = new PeopleModel(payload.User || {});
    this.UserExtra = new UserExtraModel(payload.UserExtra || {});
  }

  public hasValidSession(): boolean {
    if (this.session === undefined  || this.session === '' || this.session === null) {
      return false;
    }else{
      return true;
    }
  }

}
