/**
Copyright: 2024 Contrast Security, Inc
  Contact: support@contrastsecurity.com
  License: Commercial

  NOTICE: This Software and the patented inventions embodied within may only be
  used as part of Contrast Security’s commercial offerings. Even though it is
  made available through public repositories, use of this Software is subject to
  the applicable End User Licensing Agreement found at
  https://www.contrastsecurity.com/enduser-terms-0317a or as otherwise agreed
  between Contrast Security and the End User. The Software may not be reverse
  engineered, modified, repackaged, sold, redistributed or otherwise used in a
  way not consistent with the End User License Agreement.
*/
/**
 * @module lib/reporter/models/AppActivity/Inventory
 */

'use strict';

/**
 * Holds inventory data for AppActivity messages
 * @prop browsers
 * @prop techs
 * @prop queries
 */
class Inventory {
  constructor() {
    this.browsers = new Set();
    this.techs = new Set();
    this.queries = 0;
  }

  /**
   * Adds data to internal collections. Dispatches to the appropriate
   * method based on data attributes.
   */
  addData(data = {}) {
    if (data.techs) {
      this.addTech(data.techs);
    }
    if (data.browsers) {
      this.addBrowser(data.browsers);
    }
  }

  /**
   * Adds tech to internal collection.
   */
  addTech(tech) {
    this.techs.add(tech);
  }

  /**
   * Adds browsers to internal collection.
   */
  addBrowser(browser) {
    this.browsers.add(browser);
  }

  /**
   * Render the object so that it can be stringified and consumed by TeamServer
   */
  toSerializable() {
    return {
      browsers: Array.from(this.browsers),
      technologies: Array.from(this.techs),
      queriesMonitored: this.queries
    };
  }
}

module.exports = Inventory;
