# Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
# frozen_string_literal: true

require 'contrast/utils/object_share'

module Contrast
  module Agent
    module Reporting
      # This module will hold all the settings from the TS responce
      module Settings
        # Application level settings for the Assess featureset.
        # Used for the FeatureSet TS response
        class AssessServerFeature
          # Assess rules to disable for this application.
          #
          # @return disabled_rules [Array<AssessRuleID>] Array with string rule_ids
          def disabled_rules
            @_disabled_rules ||= []
          end

          # @param disabled_rules [Array<AssessRuleID>] with AssessRuleID strings
          # @return disabled_rules [Array<AssessRuleID>] Array with string rule_ids
          def disabled_rules= disabled_rules
            @_disabled_rules = disabled_rules if disabled_rules.is_a? Array
          end

          # Indicate if the assess feature set is enabled for this server or not.
          #
          # @return enabled [Boolean]
          def enabled?
            @_enabled
          end

          # Set the enabled
          #
          # @param enabled [Boolean]
          # @return enabled [Boolean]
          def enabled= enabled
            @_enabled = enabled if !!enabled == enabled
          end

          # Used to control the sampling feature in the agent.
          #
          # @return sampling [Hash<AssessSampling>] Hash of AssessSampling: {
          #  baseline          [Integer] The number of baseline requests to take before switching to sampling
          #                               for the window.
          #  enabled           [Boolean] If the sampling feature should be used or not.
          #  frequency         [Integer] The number of requests to skip before observing during the sampling
          #                               window after the baseline.
          #  responseFrequency [Integer]
          #  window            [Integer]
          # }
          def sampling
            @_sampling ||= {}
          end

          # set sampling
          #
          # @param sampling [Hash<AssessSampling>] Hash of AssessSampling: {
          #  baseline          [Integer] The number of baseline requests to take before switching to sampling
          #                               for the window.
          #  enabled           [Boolean] If the sampling feature should be used or not.
          #  frequency         [Integer] The number of requests to skip before observing during the sampling
          #                               window after the baseline.
          #  responseFrequency [Integer]
          #  window            [Integer]
          # }
          # @return sampling [Hash<AssessSampling>] Hash of AssessSampling: {
          #  baseline          [Integer] The number of baseline requests to take before switching to sampling
          #                               for the window.
          #  enabled           [Boolean] If the sampling feature should be used or not.
          #  frequency         [Integer] The number of requests to skip before observing during the sampling
          #                               window after the baseline.
          #  responseFrequency [Integer]
          #  window            [Integer]
          # }
          def sampling= sampling
            @_sampling = sampling if sampling.is_a? Hash
          end

          # The sanitizers defined by the user for use by the agent on this server for this organization.
          #
          # @return sanitizers [Array<AssessCustomRules>] AssessCustomRules
          #   Api   [String], Rules [Array[RulesID]]
          #   tags  [Array[String]]
          #   uuid  [String]
          def sanitizers
            @_sanitizers ||= []
          end

          # set sanitizer
          #
          # @param sanitizers [Array<AssessCustomRules>] of AssessCustomRule: {
          #   Api   [String], Rules [Array[RulesID]]
          #   tags  [Array[String]]
          #   uuid  [String]
          # }
          # @return sanitizers [Array<AssessCustomRules>] AssessCustomRules
          #   Api   [String], Rules [Array[RulesID]]
          #   tags  [Array[String]]
          #   uuid  [String]
          def sanitizers= sanitizers
            @_sanitizers = sanitizers if sanitizers.is_a? Array
          end

          # The validators defined by the user for use by the agent on this server for this organization.
          #
          # @return validators [Array<AssessCustomRules>] of AssessCustomRule: {
          #   Api   [String], Rules [Array[RulesID]]
          #   tags  [Array[String]]
          #   uuid  [String]
          # }
          def validators
            @_validators ||= []
          end

          # The validators defined by the user for use by the agent on this server for this organization.
          #
          # @param validators [Array<AssessCustomRules>] of AssessCustomRule: {
          #   Api   [String], Rules [Array[RulesID]]
          #   tags  [Array[String]]
          #   uuid  [String]
          # }
          # @return validators [Array<AssessCustomRules>] of AssessCustomRule: {
          #   Api   [String], Rules [Array[RulesID]]
          #   tags  [Array[String]]
          #   uuid  [String]
          # }
          def validators= validators
            @_validators = validators if validators.is_a? Array
          end
        end
      end
    end
  end
end