{"size": 1790, "ext": "js", "max_stars_repo_path": "lib/Model/SoftwareUpdate.js", "max_stars_repo_name": "residently/huejay", "max_stars_repo_stars_event_min_datetime": "2015-11-29T21:22:22.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-26T19:41:07.000Z", "max_issues_repo_path": "lib/Model/SoftwareUpdate.js", "max_issues_repo_name": "residently/huejay", "max_issues_repo_issues_event_min_datetime": "2015-09-29T15:44:00.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-09T21:28:18.000Z", "max_forks_repo_path": "lib/Model/SoftwareUpdate.js", "max_forks_repo_name": "residently/huejay", "max_forks_repo_forks_event_min_datetime": "2016-02-15T13:35:45.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-26T09:20:52.000Z"}
{"max_stars_count": 438, "max_issues_count": 117, "max_forks_count": 60, "avg_line_length": 17.7227722772, "max_line_length": 64, "alphanum_fraction": 0.6156424581}
'use strict';

let Attributes = require('./Attributes');

const UPDATE_STATE_MAP = {
  0: 'NO_UPDATE',
  1: 'DOWNLOADING',
  2: 'READY_TO_INSTALL',
  3: 'INSTALLING',
}

/**
 * Software update object
 *
 * Software update details
 */
class SoftwareUpdate {
  /**
   * Constructor
   *
   * @param {Object} attributes Attributes
   */
  constructor(attributes) {
    this.attributes = new Attributes(attributes);
  }

  /**
   * Get state
   *
   * @return {string} Update state
   */
  get state() {
    return UPDATE_STATE_MAP[this.attributes.get('updatestate')];
  }

  /**
   * Is checking for update
   *
   * @return {Boolean} True if checking for update, false if not
   */
  get checkingEnabled() {
    return Boolean(this.attributes.get('checkforupdate'));
  }

  /**
   * Is bridge updatable
   *
   * @return {Boolean} Is bridge updatable
   */
  get bridge() {
    return Boolean(this.attributes.get('devicetypes').bridge);
  }

  /**
   * Get updatable lights
   *
   * @return {array} List of updatable lights
   */
  get lights() {
    return this.attributes.get('devicetypes').lights;
  }

  /**
   * Get updatable sensors
   *
   * @return {array} List of updatable sensors
   */
  get sensors() {
    return this.attributes.get('devicetypes').sensors;
  }

  /**
   * Get release url
   *
   * @return {string} Release url
   */
  get releaseUrl() {
    return this.attributes.get('url');
  }

  /**
   * Get release notes
   *
   * @return {string} Release notes
   */
  get releaseNotes() {
    return this.attributes.get('text');
  }

  /**
   * Is install notification enabled
   *
   * @return {Boolean} True if enabled, false if not
   */
  get installNotificationEnabled() {
    return Boolean(this.attributes.get('notify'));
  }
}

module.exports = SoftwareUpdate;
