/**
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.
*/
'use strict';

const { settings } = require('@contrast/protobuf-api');

const CustomRuleFeature = require('./custom-rule-feature');
const Sampling = require('./sampling');
const { ASSESS_STACKTRACES } = require('../../enums');

function AssessFeatures({
  disabledRules = [],
  dynamicSources,
  enabled,
  identityTagging,
  propagators = [],
  responseScanning,
  rules,
  sampling,
  sanitizers = [],
  stacktraces,
  sources,
  taggers,
  validatorScopes,
  validators = []
} = {}) {
  return new settings.AssessFeatures([
    enabled, //                                                   1              enabled
    dynamicSources, //                                            2      dynamic_sources
    sources, //                                                   3              sources
    rules, //                                                     4                rules
    propagators, //                                               5          propagators
    taggers, //                                                   6              taggers
    responseScanning, //                                          7    response_scanning
    AssessStacktrace(stacktraces), //                             8          stacktraces
    validatorScopes, //                                           9     validator_scopes
    identityTagging, //                                          10     identity_tagging
    sanitizers.map(CustomRuleFeature).map(s => s.array), //      11           sanitizers
    validators.map(CustomRuleFeature).map(v => v.array), //      12           validators
    disabledRules, //                                            13       disabled_rules (deprecated)
    Sampling(sampling).array, //                                 14             sampling
    undefined, //                                                15                    -
    undefined, //                                                16                    -
    undefined, //                                                17                    -
    undefined, //                                                18                    -
    [] //                                                        19  dynamic_sources_map
  ]);
}

function AssessStacktrace(stacktraces) {
  return ASSESS_STACKTRACES[stacktraces];
}

module.exports = AssessFeatures;
