text: "use strict";
  Object.defineProperty(exports, "__esModule", { value: true });
  const jovo_core_1 = require("jovo-core");
  const _get = require("lodash.get");
  const _merge = require("lodash.merge");
  class BasicLogging {
      constructor(config) {
          this.config = {
              enabled: true,
              logging: undefined,
              request: false,
              requestObjects: [],
              response: false,
              responseObjects: [],
              space: '\t',
              styling: false
          };
          this.requestLogger = (handleRequest) => {
              if (jovo_core_1.Logger.isLogLevel(jovo_core_1.LogLevel.VERBOSE)) {
                  jovo_core_1.Log.verbose(jovo_core_1.Log.subheader(`Request JSON`, 'jovo-framework'));
                  jovo_core_1.Log.yellow().verbose(JSON.stringify(handleRequest.host.getRequestObject(), null, this.config.space));
                  return;
              }
              if (!this.config.request) {
                  return;
              }
              if (this.config.requestObjects && this.config.requestObjects.length > 0) {
                  this.config.requestObjects.forEach((path) => {
                      console.log(// tslint:disable-line:no-console
                      JSON.stringify(_get(handleRequest.host.getRequestObject(), path), null, this.config.space));
                  });
              }
              else {
                  console.log(// tslint:disable-line:no-console
                  JSON.stringify(handleRequest.host.getRequestObject(), null, this.config.space));
              }
          };
          this.responseLogger = (handleRequest) => {
              if (jovo_core_1.Logger.isLogLevel(jovo_core_1.LogLevel.VERBOSE)) {
                  jovo_core_1.Log.verbose(jovo_core_1.Log.subheader(`Response JSON`, 'jovo-framework'));
                  jovo_core_1.Log.yellow().verbose(JSON.stringify(handleRequest.jovo.$response, null, this.config.space));
                  return;
              }
              if (!this.config.response) {
                  return;
              }
              if (!handleRequest.jovo) {
                  return;
              }
              if (this.config.responseObjects && this.config.responseObjects.length > 0) {
                  this.config.responseObjects.forEach((path) => {
                      if (!handleRequest.jovo) {
                          return;
                      }
                      console.log(// tslint:disable-line:no-console
                      JSON.stringify(_get(handleRequest.jovo.$response, path), null, this.config.space));
                  });
              }
              else {
                  console.log(// tslint:disable-line:no-console
                  this.style(JSON.stringify(handleRequest.jovo.$response, null, this.config.space)));
              }
          };
          if (config) {
              this.config = _merge(this.config, config);
          }
          // tslint:disable
          this.requestLogger = this.requestLogger.bind(this);
          this.responseLogger = this.responseLogger.bind(this);
          // tslint:enable
      }
      install(app) {
          if (this.config.logging === true) {
              this.config.request = true;
              this.config.response = true;
          }
          else if (this.config.logging === false) {
              this.config.request = false;
              this.config.response = false;
          }
          app.on('request', this.requestLogger);
          app.on('after.response', this.responseLogger);
      }
      uninstall(app) {
          app.removeListener('request', this.requestLogger);
          app.removeListener('after.response', this.responseLogger);
      }
      style(text) {
          if (this.config.styling) {
              text = text.replace(/<speak>(.+?)<\/speak>/g, `<speak>\x1b[36m$1\x1b[0m</speak>`);
              text = text.replace(/"_JOVO_STATE_": "(.+?)"/g, `"_JOVO_STATE_": "\x1b[33m$1\x1b[0m"`);
          }
          return text;
      }
  }
  exports.BasicLogging = BasicLogging;
  //# sourceMappingURL=BasicLogging.js.map