/**
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/models/SourceEvent
 */

'use strict';

const _ = require('lodash');
const ApplicationContext = require('./application-context');

class SourceEvent extends ApplicationContext {
  /**
   * @param {Object} context Application context data
   * @param {IncomingMessage} context._incomingMessage Raw http request
   * @param {ServerResponse} context._serverResponse Raw http response
   * @param {*} [context.data] The data triggering event
   * @param {Object} context.dataOwner Object where `data` exists at `dataPath`
   * @param {String} context.dataPath Path to the `data` found on `owner`
   * @param {String} context.id Identifier of source, e.g. express, https
   * @param {Request} context.request Our application model of a request
   * @param {Response} context.response Our application model of a response
   * @param {String} context.type The input type, e.g. HEADER, BODY
   */
  constructor(context) {
    super(context);
    this._incomingMessage = context._incomingMessage;
    this._serverResponse = context._serverResponse;
    this.data = _.get(
      context,
      'data',
      _.get(context.dataOwner, context.dataPath)
    );
    this.request = context.request;
    this.response = context.response;
  }
}

module.exports = SourceEvent;
