import { DEFAULT_INTERVAL } from './constants';
import LoggerFactory from './logger/LoggerFactory';
import MetricsAggregator from './metrics/MetricsAggregator';

export default class Monyt {
  /**
   * @param {Object} [options={}] - Options to initialize Monyt.
   * @param {string} [options.interval=30000] - Interval to listen aggregate.
   * @param {Array<Metrics>} [options.metricses=[]] - List of Metrics to aggregate.
   * @param {Array<Sender>} [options.senders=[]] - List of sender to send metricses.
   * @param {Promise} [options.listener=new Promise()] - Listener of MetricsAggregator.
   * @param {string} [options.prefix=''] - Prefix of metrics name.
   * @param {Object} [options.aggregator=new MetricsAggregator({...options, interval: this.interval})] - Instance of MetricsAggregator.
   * @param {Logger} [options.logger=LoggerFactory.FACTORY] - Logger Class to use.
   * @param {boolean} [options.replaceConsole=false] - Replace Console with Logger.
   * @return {Monyt} - new Monyt Instances.
   */
  constructor(options = {}) {
    this.interval = options.interval || DEFAULT_INTERVAL;
    this.senders = options.senders || [];
    this.listener = '';
    this.aggregator = options.aggregator || new MetricsAggregator({ ...options, interval: this.interval });
    this.replaceConsole = options.replaceConsole || false;
    options.logger && LoggerFactory.setFactory(options.logger);
  }

  /**
   * Start to aggregate and send metricses.
   * Replace Console to default logger when replaceConsole is true.
   * @param {Function} callback - callback function that returns result promises of senders.
   * @returns {Number} - interval listener id.
   */
  listen(callback) {
    this.replaceConsole && this.getLogger({ replaceConsole: this.replaceConsole });
    return this.aggregator.listen((metricses)=> {
      Promise.all(this.senders.map(sender => sender.send(metricses)))
        .then(results => callback && callback(Promise.resolve(results)))
        .catch(error => callback && callback(Promise.reject(error)));
    });
  }

  /**
   * Stop to listen.
   * @returns {Number} - result of clearListener.
   */
  stop() {
    return this.aggregator.stop();
  }

  /**
   * @returns {Logger} logger - Default logger instance.
   */
  getLogger(options) {
    return LoggerFactory.getLogger(options);
  }

  /**
   * @returns {Array} middlewares - List of middlewares to mark and log requests and errors.
   */
  middlewares() {
    return [this.aggregator.markMiddleware(), LoggerFactory.logMiddleware()];
  }
}

@@ -2177,32 +2177,325 @@
 p();%0A  %7D%0A%0A  /**%0A
+   * @param %7BObject%7D %5Boptions=%7B%7D%5D - Options to initialize logger instance.%0A   * @param %7Bstring%7D %5Boptions.category=app%5D - Category of logger.%0A   * @param %7Bstring%7D %5Boptions.level=info%5D - Level to log.%0A   * @param %7Bboolean%7D %5Boptions.replaceConsole=false%5D - Flag to switch replaceConsole options.%0A
    * @returns %7BL
@@ -2531,24 +2531,24 @@
 r instance.%0A
-
    */%0A  getL
@@ -2749,16 +2749,17 @@
 return %5B
+ 
 this.agg
@@ -2813,16 +2813,17 @@
 leware()
+ 
 %5D;%0A  %7D%0A%7D

Add missing ESDoc