# encoding: utf-8
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.

module Azure::AlertsManagement::Mgmt::V2019_05_05_preview
  #
  # AlertsManagement Client
  #
  class ActionRules
    include MsRestAzure

    #
    # Creates and initializes a new instance of the ActionRules class.
    # @param client service class for accessing basic functionality.
    #
    def initialize(client)
      @client = client
    end

    # @return [AlertsManagementClient] reference to the AlertsManagementClient
    attr_reader :client

    #
    # Get all action rule in a given subscription
    #
    # List all action rules of the subscription and given input filters
    #
    # @param target_resource_group [String] Filter by target resource group name.
    # Default value is select all.
    # @param target_resource_type [String] Filter by target resource type. Default
    # value is select all.
    # @param target_resource [String] Filter by target resource( which is full ARM
    # ID) Default value is select all.
    # @param severity [Severity] Filter by severity.  Default value is select all.
    # Possible values include: 'Sev0', 'Sev1', 'Sev2', 'Sev3', 'Sev4'
    # @param monitor_service [MonitorService] Filter by monitor service which
    # generates the alert instance. Default value is select all. Possible values
    # include: 'Application Insights', 'ActivityLog Administrative', 'ActivityLog
    # Security', 'ActivityLog Recommendation', 'ActivityLog Policy', 'ActivityLog
    # Autoscale', 'Log Analytics', 'Nagios', 'Platform', 'SCOM', 'ServiceHealth',
    # 'SmartDetector', 'VM Insights', 'Zabbix'
    # @param impacted_scope [String] filter by impacted/target scope (provide comma
    # separated list for multiple scopes). The value should be an well constructed
    # ARM id of the scope.
    # @param description [String] filter by alert rule description
    # @param alert_rule_id [String] filter by alert rule id
    # @param action_group [String] filter by action group configured as part of
    # action rule
    # @param name [String] filter by action rule name
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Array<ActionRule>] operation results.
    #
    def list_by_subscription(target_resource_group:nil, target_resource_type:nil, target_resource:nil, severity:nil, monitor_service:nil, impacted_scope:nil, description:nil, alert_rule_id:nil, action_group:nil, name:nil, custom_headers:nil)
      first_page = list_by_subscription_as_lazy(target_resource_group:target_resource_group, target_resource_type:target_resource_type, target_resource:target_resource, severity:severity, monitor_service:monitor_service, impacted_scope:impacted_scope, description:description, alert_rule_id:alert_rule_id, action_group:action_group, name:name, custom_headers:custom_headers)
      first_page.get_all_items
    end

    #
    # Get all action rule in a given subscription
    #
    # List all action rules of the subscription and given input filters
    #
    # @param target_resource_group [String] Filter by target resource group name.
    # Default value is select all.
    # @param target_resource_type [String] Filter by target resource type. Default
    # value is select all.
    # @param target_resource [String] Filter by target resource( which is full ARM
    # ID) Default value is select all.
    # @param severity [Severity] Filter by severity.  Default value is select all.
    # Possible values include: 'Sev0', 'Sev1', 'Sev2', 'Sev3', 'Sev4'
    # @param monitor_service [MonitorService] Filter by monitor service which
    # generates the alert instance. Default value is select all. Possible values
    # include: 'Application Insights', 'ActivityLog Administrative', 'ActivityLog
    # Security', 'ActivityLog Recommendation', 'ActivityLog Policy', 'ActivityLog
    # Autoscale', 'Log Analytics', 'Nagios', 'Platform', 'SCOM', 'ServiceHealth',
    # 'SmartDetector', 'VM Insights', 'Zabbix'
    # @param impacted_scope [String] filter by impacted/target scope (provide comma
    # separated list for multiple scopes). The value should be an well constructed
    # ARM id of the scope.
    # @param description [String] filter by alert rule description
    # @param alert_rule_id [String] filter by alert rule id
    # @param action_group [String] filter by action group configured as part of
    # action rule
    # @param name [String] filter by action rule name
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
    #
    def list_by_subscription_with_http_info(target_resource_group:nil, target_resource_type:nil, target_resource:nil, severity:nil, monitor_service:nil, impacted_scope:nil, description:nil, alert_rule_id:nil, action_group:nil, name:nil, custom_headers:nil)
      list_by_subscription_async(target_resource_group:target_resource_group, target_resource_type:target_resource_type, target_resource:target_resource, severity:severity, monitor_service:monitor_service, impacted_scope:impacted_scope, description:description, alert_rule_id:alert_rule_id, action_group:action_group, name:name, custom_headers:custom_headers).value!
    end

    #
    # Get all action rule in a given subscription
    #
    # List all action rules of the subscription and given input filters
    #
    # @param target_resource_group [String] Filter by target resource group name.
    # Default value is select all.
    # @param target_resource_type [String] Filter by target resource type. Default
    # value is select all.
    # @param target_resource [String] Filter by target resource( which is full ARM
    # ID) Default value is select all.
    # @param severity [Severity] Filter by severity.  Default value is select all.
    # Possible values include: 'Sev0', 'Sev1', 'Sev2', 'Sev3', 'Sev4'
    # @param monitor_service [MonitorService] Filter by monitor service which
    # generates the alert instance. Default value is select all. Possible values
    # include: 'Application Insights', 'ActivityLog Administrative', 'ActivityLog
    # Security', 'ActivityLog Recommendation', 'ActivityLog Policy', 'ActivityLog
    # Autoscale', 'Log Analytics', 'Nagios', 'Platform', 'SCOM', 'ServiceHealth',
    # 'SmartDetector', 'VM Insights', 'Zabbix'
    # @param impacted_scope [String] filter by impacted/target scope (provide comma
    # separated list for multiple scopes). The value should be an well constructed
    # ARM id of the scope.
    # @param description [String] filter by alert rule description
    # @param alert_rule_id [String] filter by alert rule id
    # @param action_group [String] filter by action group configured as part of
    # action rule
    # @param name [String] filter by action rule name
    # @param [Hash{String => String}] A hash of custom headers that will be added
    # to the HTTP request.
    #
    # @return [Concurrent::Promise] Promise object which holds the HTTP response.
    #
    def list_by_subscription_async(target_resource_group:nil, target_resource_type:nil, target_resource:nil, severity:nil, monitor_service:nil, impacted_scope:nil, description:nil, alert_rule_id:nil, action_group:nil, name:nil, custom_headers:nil)
      fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
      @client.api_version = '2019-05-05-preview'


      request_headers = {}
      request_headers['Content-Type'] = 'application/json; charset=utf-8'

      # Set Headers
      request_headers['x-ms-client-request-id'] = SecureRandom.uuid
      request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
      path_template = 'subscriptions/{subscriptionId}/providers/Microsoft.AlertsManagement/actionRules'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'subscriptionId' => @client.subscription_id},
          query_params: {'targetResourceGroup' => target_resource_group,'targetResourceType' => target_resource_type,'targetResource' => target_resource,'severity' => severity,'monitorService' => monitor_service,'impactedScope' => impacted_scope,'description' => description,'alertRuleId' => alert_rule_id,'actionGroup' => action_group,'name' => name,'api-version' => @client.api_version},
          headers: request_headers.merge(custom_headers || {}),
          base_url: request_url
      }
      promise = @client.make_request_async(:get, path_template, options)

      promise = promise.then do |result|
        http_response = result.response
        status_code = http_response.status
        response_content = http_response.body
        unless status_code == 200
          error_model = JSON.load(response_content)
          fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
        end

        result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
        result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
        result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
        # Deserialize Response
        if status_code == 200
          begin
            parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
            result_mapper = Azure::AlertsManagement::Mgmt::V2019_05_05_preview::Models::ActionRulesList.mapper()
            result.body = @client.deserialize(result_mapper, parsed_response)
          rescue Exception => e
            fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
          end
        end

        result
      end

      promise.execute
    end

    #
    # Get all action rules created in a resource group
    #
    # List all action rules of the subscription, created in given resource group
    # and given input filters
    #
    # @param resource_group_name [String] Resource group name where the resource is
    # created.
    # @param target_resource_group [String] Filter by target resource group name.
    # Default value is select all.
    # @param target_resource_type [String] Filter by target resource type. Default
    # value is select all.
    # @param target_resource [String] Filter by target resource( which is full ARM
    # ID) Default value is select all.
    # @param severity [Severity] Filter by severity.  Default value is select all.
    # Possible values include: 'Sev0', 'Sev1', 'Sev2', 'Sev3', 'Sev4'
    # @param monitor_service [MonitorService] Filter by monitor service which
    # generates the alert instance. Default value is select all. Possible values
    # include: 'Application Insights', 'ActivityLog Administrative', 'ActivityLog
    # Security', 'ActivityLog Recommendation', 'ActivityLog Policy', 'ActivityLog
    # Autoscale', 'Log Analytics', 'Nagios', 'Platform', 'SCOM', 'ServiceHealth',
    # 'SmartDetector', 'VM Insights', 'Zabbix'
    # @param impacted_scope [String] filter by impacted/target scope (provide comma
    # separated list for multiple scopes). The value should be an well constructed
    # ARM id of the scope.
    # @param description [String] filter by alert rule description
    # @param alert_rule_id [String] filter by alert rule id
    # @param action_group [String] filter by action group configured as part of
    # action rule
    # @param name [String] filter by action rule name
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Array<ActionRule>] operation results.
    #
    def list_by_resource_group(resource_group_name, target_resource_group:nil, target_resource_type:nil, target_resource:nil, severity:nil, monitor_service:nil, impacted_scope:nil, description:nil, alert_rule_id:nil, action_group:nil, name:nil, custom_headers:nil)
      first_page = list_by_resource_group_as_lazy(resource_group_name, target_resource_group:target_resource_group, target_resource_type:target_resource_type, target_resource:target_resource, severity:severity, monitor_service:monitor_service, impacted_scope:impacted_scope, description:description, alert_rule_id:alert_rule_id, action_group:action_group, name:name, custom_headers:custom_headers)
      first_page.get_all_items
    end

    #
    # Get all action rules created in a resource group
    #
    # List all action rules of the subscription, created in given resource group
    # and given input filters
    #
    # @param resource_group_name [String] Resource group name where the resource is
    # created.
    # @param target_resource_group [String] Filter by target resource group name.
    # Default value is select all.
    # @param target_resource_type [String] Filter by target resource type. Default
    # value is select all.
    # @param target_resource [String] Filter by target resource( which is full ARM
    # ID) Default value is select all.
    # @param severity [Severity] Filter by severity.  Default value is select all.
    # Possible values include: 'Sev0', 'Sev1', 'Sev2', 'Sev3', 'Sev4'
    # @param monitor_service [MonitorService] Filter by monitor service which
    # generates the alert instance. Default value is select all. Possible values
    # include: 'Application Insights', 'ActivityLog Administrative', 'ActivityLog
    # Security', 'ActivityLog Recommendation', 'ActivityLog Policy', 'ActivityLog
    # Autoscale', 'Log Analytics', 'Nagios', 'Platform', 'SCOM', 'ServiceHealth',
    # 'SmartDetector', 'VM Insights', 'Zabbix'
    # @param impacted_scope [String] filter by impacted/target scope (provide comma
    # separated list for multiple scopes). The value should be an well constructed
    # ARM id of the scope.
    # @param description [String] filter by alert rule description
    # @param alert_rule_id [String] filter by alert rule id
    # @param action_group [String] filter by action group configured as part of
    # action rule
    # @param name [String] filter by action rule name
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
    #
    def list_by_resource_group_with_http_info(resource_group_name, target_resource_group:nil, target_resource_type:nil, target_resource:nil, severity:nil, monitor_service:nil, impacted_scope:nil, description:nil, alert_rule_id:nil, action_group:nil, name:nil, custom_headers:nil)
      list_by_resource_group_async(resource_group_name, target_resource_group:target_resource_group, target_resource_type:target_resource_type, target_resource:target_resource, severity:severity, monitor_service:monitor_service, impacted_scope:impacted_scope, description:description, alert_rule_id:alert_rule_id, action_group:action_group, name:name, custom_headers:custom_headers).value!
    end

    #
    # Get all action rules created in a resource group
    #
    # List all action rules of the subscription, created in given resource group
    # and given input filters
    #
    # @param resource_group_name [String] Resource group name where the resource is
    # created.
    # @param target_resource_group [String] Filter by target resource group name.
    # Default value is select all.
    # @param target_resource_type [String] Filter by target resource type. Default
    # value is select all.
    # @param target_resource [String] Filter by target resource( which is full ARM
    # ID) Default value is select all.
    # @param severity [Severity] Filter by severity.  Default value is select all.
    # Possible values include: 'Sev0', 'Sev1', 'Sev2', 'Sev3', 'Sev4'
    # @param monitor_service [MonitorService] Filter by monitor service which
    # generates the alert instance. Default value is select all. Possible values
    # include: 'Application Insights', 'ActivityLog Administrative', 'ActivityLog
    # Security', 'ActivityLog Recommendation', 'ActivityLog Policy', 'ActivityLog
    # Autoscale', 'Log Analytics', 'Nagios', 'Platform', 'SCOM', 'ServiceHealth',
    # 'SmartDetector', 'VM Insights', 'Zabbix'
    # @param impacted_scope [String] filter by impacted/target scope (provide comma
    # separated list for multiple scopes). The value should be an well constructed
    # ARM id of the scope.
    # @param description [String] filter by alert rule description
    # @param alert_rule_id [String] filter by alert rule id
    # @param action_group [String] filter by action group configured as part of
    # action rule
    # @param name [String] filter by action rule name
    # @param [Hash{String => String}] A hash of custom headers that will be added
    # to the HTTP request.
    #
    # @return [Concurrent::Promise] Promise object which holds the HTTP response.
    #
    def list_by_resource_group_async(resource_group_name, target_resource_group:nil, target_resource_type:nil, target_resource:nil, severity:nil, monitor_service:nil, impacted_scope:nil, description:nil, alert_rule_id:nil, action_group:nil, name:nil, custom_headers:nil)
      fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
      fail ArgumentError, 'resource_group_name is nil' if resource_group_name.nil?
      @client.api_version = '2019-05-05-preview'


      request_headers = {}
      request_headers['Content-Type'] = 'application/json; charset=utf-8'

      # Set Headers
      request_headers['x-ms-client-request-id'] = SecureRandom.uuid
      request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
      path_template = 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.AlertsManagement/actionRules'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'subscriptionId' => @client.subscription_id,'resourceGroupName' => resource_group_name},
          query_params: {'targetResourceGroup' => target_resource_group,'targetResourceType' => target_resource_type,'targetResource' => target_resource,'severity' => severity,'monitorService' => monitor_service,'impactedScope' => impacted_scope,'description' => description,'alertRuleId' => alert_rule_id,'actionGroup' => action_group,'name' => name,'api-version' => @client.api_version},
          headers: request_headers.merge(custom_headers || {}),
          base_url: request_url
      }
      promise = @client.make_request_async(:get, path_template, options)

      promise = promise.then do |result|
        http_response = result.response
        status_code = http_response.status
        response_content = http_response.body
        unless status_code == 200
          error_model = JSON.load(response_content)
          fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
        end

        result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
        result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
        result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
        # Deserialize Response
        if status_code == 200
          begin
            parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
            result_mapper = Azure::AlertsManagement::Mgmt::V2019_05_05_preview::Models::ActionRulesList.mapper()
            result.body = @client.deserialize(result_mapper, parsed_response)
          rescue Exception => e
            fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
          end
        end

        result
      end

      promise.execute
    end

    #
    # Get action rule by name
    #
    # Get a specific action rule
    #
    # @param resource_group_name [String] Resource group name where the resource is
    # created.
    # @param action_rule_name [String] The name of action rule that needs to be
    # fetched
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [ActionRule] operation results.
    #
    def get_by_name(resource_group_name, action_rule_name, custom_headers:nil)
      response = get_by_name_async(resource_group_name, action_rule_name, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Get action rule by name
    #
    # Get a specific action rule
    #
    # @param resource_group_name [String] Resource group name where the resource is
    # created.
    # @param action_rule_name [String] The name of action rule that needs to be
    # fetched
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
    #
    def get_by_name_with_http_info(resource_group_name, action_rule_name, custom_headers:nil)
      get_by_name_async(resource_group_name, action_rule_name, custom_headers:custom_headers).value!
    end

    #
    # Get action rule by name
    #
    # Get a specific action rule
    #
    # @param resource_group_name [String] Resource group name where the resource is
    # created.
    # @param action_rule_name [String] The name of action rule that needs to be
    # fetched
    # @param [Hash{String => String}] A hash of custom headers that will be added
    # to the HTTP request.
    #
    # @return [Concurrent::Promise] Promise object which holds the HTTP response.
    #
    def get_by_name_async(resource_group_name, action_rule_name, custom_headers:nil)
      fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
      fail ArgumentError, 'resource_group_name is nil' if resource_group_name.nil?
      fail ArgumentError, 'action_rule_name is nil' if action_rule_name.nil?
      @client.api_version = '2019-05-05-preview'


      request_headers = {}
      request_headers['Content-Type'] = 'application/json; charset=utf-8'

      # Set Headers
      request_headers['x-ms-client-request-id'] = SecureRandom.uuid
      request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
      path_template = 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.AlertsManagement/actionRules/{actionRuleName}'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'subscriptionId' => @client.subscription_id,'resourceGroupName' => resource_group_name,'actionRuleName' => action_rule_name},
          query_params: {'api-version' => @client.api_version},
          headers: request_headers.merge(custom_headers || {}),
          base_url: request_url
      }
      promise = @client.make_request_async(:get, path_template, options)

      promise = promise.then do |result|
        http_response = result.response
        status_code = http_response.status
        response_content = http_response.body
        unless status_code == 200
          error_model = JSON.load(response_content)
          fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
        end

        result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
        result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
        result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
        # Deserialize Response
        if status_code == 200
          begin
            parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
            result_mapper = Azure::AlertsManagement::Mgmt::V2019_05_05_preview::Models::ActionRule.mapper()
            result.body = @client.deserialize(result_mapper, parsed_response)
          rescue Exception => e
            fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
          end
        end

        result
      end

      promise.execute
    end

    #
    # Create/update an action rule
    #
    # Creates/Updates a specific action rule
    #
    # @param resource_group_name [String] Resource group name where the resource is
    # created.
    # @param action_rule_name [String] The name of action rule that needs to be
    # created/updated
    # @param action_rule [ActionRule] action rule to be created/updated
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [ActionRule] operation results.
    #
    def create_update(resource_group_name, action_rule_name, action_rule, custom_headers:nil)
      response = create_update_async(resource_group_name, action_rule_name, action_rule, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Create/update an action rule
    #
    # Creates/Updates a specific action rule
    #
    # @param resource_group_name [String] Resource group name where the resource is
    # created.
    # @param action_rule_name [String] The name of action rule that needs to be
    # created/updated
    # @param action_rule [ActionRule] action rule to be created/updated
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
    #
    def create_update_with_http_info(resource_group_name, action_rule_name, action_rule, custom_headers:nil)
      create_update_async(resource_group_name, action_rule_name, action_rule, custom_headers:custom_headers).value!
    end

    #
    # Create/update an action rule
    #
    # Creates/Updates a specific action rule
    #
    # @param resource_group_name [String] Resource group name where the resource is
    # created.
    # @param action_rule_name [String] The name of action rule that needs to be
    # created/updated
    # @param action_rule [ActionRule] action rule to be created/updated
    # @param [Hash{String => String}] A hash of custom headers that will be added
    # to the HTTP request.
    #
    # @return [Concurrent::Promise] Promise object which holds the HTTP response.
    #
    def create_update_async(resource_group_name, action_rule_name, action_rule, custom_headers:nil)
      fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
      fail ArgumentError, 'resource_group_name is nil' if resource_group_name.nil?
      fail ArgumentError, 'action_rule_name is nil' if action_rule_name.nil?
      fail ArgumentError, 'action_rule is nil' if action_rule.nil?
      @client.api_version = '2019-05-05-preview'


      request_headers = {}
      request_headers['Content-Type'] = 'application/json; charset=utf-8'

      # Set Headers
      request_headers['x-ms-client-request-id'] = SecureRandom.uuid
      request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?

      # Serialize Request
      request_mapper = Azure::AlertsManagement::Mgmt::V2019_05_05_preview::Models::ActionRule.mapper()
      request_content = @client.serialize(request_mapper,  action_rule)
      request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil

      path_template = 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.AlertsManagement/actionRules/{actionRuleName}'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'subscriptionId' => @client.subscription_id,'resourceGroupName' => resource_group_name,'actionRuleName' => action_rule_name},
          query_params: {'api-version' => @client.api_version},
          body: request_content,
          headers: request_headers.merge(custom_headers || {}),
          base_url: request_url
      }
      promise = @client.make_request_async(:put, path_template, options)

      promise = promise.then do |result|
        http_response = result.response
        status_code = http_response.status
        response_content = http_response.body
        unless status_code == 200
          error_model = JSON.load(response_content)
          fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
        end

        result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
        result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
        result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
        # Deserialize Response
        if status_code == 200
          begin
            parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
            result_mapper = Azure::AlertsManagement::Mgmt::V2019_05_05_preview::Models::ActionRule.mapper()
            result.body = @client.deserialize(result_mapper, parsed_response)
          rescue Exception => e
            fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
          end
        end

        result
      end

      promise.execute
    end

    #
    # Delete action rule
    #
    # Deletes a given action rule
    #
    # @param resource_group_name [String] Resource group name where the resource is
    # created.
    # @param action_rule_name [String] The name that needs to be deleted
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Boolean] operation results.
    #
    def delete(resource_group_name, action_rule_name, custom_headers:nil)
      response = delete_async(resource_group_name, action_rule_name, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Delete action rule
    #
    # Deletes a given action rule
    #
    # @param resource_group_name [String] Resource group name where the resource is
    # created.
    # @param action_rule_name [String] The name that needs to be deleted
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
    #
    def delete_with_http_info(resource_group_name, action_rule_name, custom_headers:nil)
      delete_async(resource_group_name, action_rule_name, custom_headers:custom_headers).value!
    end

    #
    # Delete action rule
    #
    # Deletes a given action rule
    #
    # @param resource_group_name [String] Resource group name where the resource is
    # created.
    # @param action_rule_name [String] The name that needs to be deleted
    # @param [Hash{String => String}] A hash of custom headers that will be added
    # to the HTTP request.
    #
    # @return [Concurrent::Promise] Promise object which holds the HTTP response.
    #
    def delete_async(resource_group_name, action_rule_name, custom_headers:nil)
      fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
      fail ArgumentError, 'resource_group_name is nil' if resource_group_name.nil?
      fail ArgumentError, 'action_rule_name is nil' if action_rule_name.nil?
      @client.api_version = '2019-05-05-preview'


      request_headers = {}
      request_headers['Content-Type'] = 'application/json; charset=utf-8'

      # Set Headers
      request_headers['x-ms-client-request-id'] = SecureRandom.uuid
      request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
      path_template = 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.AlertsManagement/actionRules/{actionRuleName}'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'subscriptionId' => @client.subscription_id,'resourceGroupName' => resource_group_name,'actionRuleName' => action_rule_name},
          query_params: {'api-version' => @client.api_version},
          headers: request_headers.merge(custom_headers || {}),
          base_url: request_url
      }
      promise = @client.make_request_async(:delete, path_template, options)

      promise = promise.then do |result|
        http_response = result.response
        status_code = http_response.status
        response_content = http_response.body
        unless status_code == 200
          error_model = JSON.load(response_content)
          fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
        end

        result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
        result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
        result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
        # Deserialize Response
        if status_code == 200
          begin
            parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
            result_mapper = {
              client_side_validation: true,
              required: false,
              serialized_name: 'parsed_response',
              type: {
                name: 'Boolean'
              }
            }
            result.body = @client.deserialize(result_mapper, parsed_response)
          rescue Exception => e
            fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
          end
        end

        result
      end

      promise.execute
    end

    #
    # Patch action rule
    #
    # Update enabled flag and/or tags for the given action rule
    #
    # @param resource_group_name [String] Resource group name where the resource is
    # created.
    # @param action_rule_name [String] The name that needs to be updated
    # @param action_rule_patch [PatchObject] Parameters supplied to the operation.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [ActionRule] operation results.
    #
    def update(resource_group_name, action_rule_name, action_rule_patch, custom_headers:nil)
      response = update_async(resource_group_name, action_rule_name, action_rule_patch, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Patch action rule
    #
    # Update enabled flag and/or tags for the given action rule
    #
    # @param resource_group_name [String] Resource group name where the resource is
    # created.
    # @param action_rule_name [String] The name that needs to be updated
    # @param action_rule_patch [PatchObject] Parameters supplied to the operation.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
    #
    def update_with_http_info(resource_group_name, action_rule_name, action_rule_patch, custom_headers:nil)
      update_async(resource_group_name, action_rule_name, action_rule_patch, custom_headers:custom_headers).value!
    end

    #
    # Patch action rule
    #
    # Update enabled flag and/or tags for the given action rule
    #
    # @param resource_group_name [String] Resource group name where the resource is
    # created.
    # @param action_rule_name [String] The name that needs to be updated
    # @param action_rule_patch [PatchObject] Parameters supplied to the operation.
    # @param [Hash{String => String}] A hash of custom headers that will be added
    # to the HTTP request.
    #
    # @return [Concurrent::Promise] Promise object which holds the HTTP response.
    #
    def update_async(resource_group_name, action_rule_name, action_rule_patch, custom_headers:nil)
      fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
      fail ArgumentError, 'resource_group_name is nil' if resource_group_name.nil?
      fail ArgumentError, 'action_rule_name is nil' if action_rule_name.nil?
      fail ArgumentError, 'action_rule_patch is nil' if action_rule_patch.nil?
      @client.api_version = '2019-05-05-preview'


      request_headers = {}
      request_headers['Content-Type'] = 'application/json; charset=utf-8'

      # Set Headers
      request_headers['x-ms-client-request-id'] = SecureRandom.uuid
      request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?

      # Serialize Request
      request_mapper = Azure::AlertsManagement::Mgmt::V2019_05_05_preview::Models::PatchObject.mapper()
      request_content = @client.serialize(request_mapper,  action_rule_patch)
      request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil

      path_template = 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.AlertsManagement/actionRules/{actionRuleName}'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'subscriptionId' => @client.subscription_id,'resourceGroupName' => resource_group_name,'actionRuleName' => action_rule_name},
          query_params: {'api-version' => @client.api_version},
          body: request_content,
          headers: request_headers.merge(custom_headers || {}),
          base_url: request_url
      }
      promise = @client.make_request_async(:patch, path_template, options)

      promise = promise.then do |result|
        http_response = result.response
        status_code = http_response.status
        response_content = http_response.body
        unless status_code == 200
          error_model = JSON.load(response_content)
          fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
        end

        result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
        result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
        result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
        # Deserialize Response
        if status_code == 200
          begin
            parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
            result_mapper = Azure::AlertsManagement::Mgmt::V2019_05_05_preview::Models::ActionRule.mapper()
            result.body = @client.deserialize(result_mapper, parsed_response)
          rescue Exception => e
            fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
          end
        end

        result
      end

      promise.execute
    end

    #
    # Get all action rule in a given subscription
    #
    # List all action rules of the subscription and given input filters
    #
    # @param next_page_link [String] The NextLink from the previous successful call
    # to List operation.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [ActionRulesList] operation results.
    #
    def list_by_subscription_next(next_page_link, custom_headers:nil)
      response = list_by_subscription_next_async(next_page_link, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Get all action rule in a given subscription
    #
    # List all action rules of the subscription and given input filters
    #
    # @param next_page_link [String] The NextLink from the previous successful call
    # to List operation.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
    #
    def list_by_subscription_next_with_http_info(next_page_link, custom_headers:nil)
      list_by_subscription_next_async(next_page_link, custom_headers:custom_headers).value!
    end

    #
    # Get all action rule in a given subscription
    #
    # List all action rules of the subscription and given input filters
    #
    # @param next_page_link [String] The NextLink from the previous successful call
    # to List operation.
    # @param [Hash{String => String}] A hash of custom headers that will be added
    # to the HTTP request.
    #
    # @return [Concurrent::Promise] Promise object which holds the HTTP response.
    #
    def list_by_subscription_next_async(next_page_link, custom_headers:nil)
      fail ArgumentError, 'next_page_link is nil' if next_page_link.nil?


      request_headers = {}
      request_headers['Content-Type'] = 'application/json; charset=utf-8'

      # Set Headers
      request_headers['x-ms-client-request-id'] = SecureRandom.uuid
      request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
      path_template = '{nextLink}'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          skip_encoding_path_params: {'nextLink' => next_page_link},
          headers: request_headers.merge(custom_headers || {}),
          base_url: request_url
      }
      promise = @client.make_request_async(:get, path_template, options)

      promise = promise.then do |result|
        http_response = result.response
        status_code = http_response.status
        response_content = http_response.body
        unless status_code == 200
          error_model = JSON.load(response_content)
          fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
        end

        result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
        result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
        result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
        # Deserialize Response
        if status_code == 200
          begin
            parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
            result_mapper = Azure::AlertsManagement::Mgmt::V2019_05_05_preview::Models::ActionRulesList.mapper()
            result.body = @client.deserialize(result_mapper, parsed_response)
          rescue Exception => e
            fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
          end
        end

        result
      end

      promise.execute
    end

    #
    # Get all action rules created in a resource group
    #
    # List all action rules of the subscription, created in given resource group
    # and given input filters
    #
    # @param next_page_link [String] The NextLink from the previous successful call
    # to List operation.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [ActionRulesList] operation results.
    #
    def list_by_resource_group_next(next_page_link, custom_headers:nil)
      response = list_by_resource_group_next_async(next_page_link, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Get all action rules created in a resource group
    #
    # List all action rules of the subscription, created in given resource group
    # and given input filters
    #
    # @param next_page_link [String] The NextLink from the previous successful call
    # to List operation.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
    #
    def list_by_resource_group_next_with_http_info(next_page_link, custom_headers:nil)
      list_by_resource_group_next_async(next_page_link, custom_headers:custom_headers).value!
    end

    #
    # Get all action rules created in a resource group
    #
    # List all action rules of the subscription, created in given resource group
    # and given input filters
    #
    # @param next_page_link [String] The NextLink from the previous successful call
    # to List operation.
    # @param [Hash{String => String}] A hash of custom headers that will be added
    # to the HTTP request.
    #
    # @return [Concurrent::Promise] Promise object which holds the HTTP response.
    #
    def list_by_resource_group_next_async(next_page_link, custom_headers:nil)
      fail ArgumentError, 'next_page_link is nil' if next_page_link.nil?


      request_headers = {}
      request_headers['Content-Type'] = 'application/json; charset=utf-8'

      # Set Headers
      request_headers['x-ms-client-request-id'] = SecureRandom.uuid
      request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
      path_template = '{nextLink}'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          skip_encoding_path_params: {'nextLink' => next_page_link},
          headers: request_headers.merge(custom_headers || {}),
          base_url: request_url
      }
      promise = @client.make_request_async(:get, path_template, options)

      promise = promise.then do |result|
        http_response = result.response
        status_code = http_response.status
        response_content = http_response.body
        unless status_code == 200
          error_model = JSON.load(response_content)
          fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
        end

        result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
        result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
        result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
        # Deserialize Response
        if status_code == 200
          begin
            parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
            result_mapper = Azure::AlertsManagement::Mgmt::V2019_05_05_preview::Models::ActionRulesList.mapper()
            result.body = @client.deserialize(result_mapper, parsed_response)
          rescue Exception => e
            fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
          end
        end

        result
      end

      promise.execute
    end

    #
    # Get all action rule in a given subscription
    #
    # List all action rules of the subscription and given input filters
    #
    # @param target_resource_group [String] Filter by target resource group name.
    # Default value is select all.
    # @param target_resource_type [String] Filter by target resource type. Default
    # value is select all.
    # @param target_resource [String] Filter by target resource( which is full ARM
    # ID) Default value is select all.
    # @param severity [Severity] Filter by severity.  Default value is select all.
    # Possible values include: 'Sev0', 'Sev1', 'Sev2', 'Sev3', 'Sev4'
    # @param monitor_service [MonitorService] Filter by monitor service which
    # generates the alert instance. Default value is select all. Possible values
    # include: 'Application Insights', 'ActivityLog Administrative', 'ActivityLog
    # Security', 'ActivityLog Recommendation', 'ActivityLog Policy', 'ActivityLog
    # Autoscale', 'Log Analytics', 'Nagios', 'Platform', 'SCOM', 'ServiceHealth',
    # 'SmartDetector', 'VM Insights', 'Zabbix'
    # @param impacted_scope [String] filter by impacted/target scope (provide comma
    # separated list for multiple scopes). The value should be an well constructed
    # ARM id of the scope.
    # @param description [String] filter by alert rule description
    # @param alert_rule_id [String] filter by alert rule id
    # @param action_group [String] filter by action group configured as part of
    # action rule
    # @param name [String] filter by action rule name
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [ActionRulesList] which provide lazy access to pages of the response.
    #
    def list_by_subscription_as_lazy(target_resource_group:nil, target_resource_type:nil, target_resource:nil, severity:nil, monitor_service:nil, impacted_scope:nil, description:nil, alert_rule_id:nil, action_group:nil, name:nil, custom_headers:nil)
      response = list_by_subscription_async(target_resource_group:target_resource_group, target_resource_type:target_resource_type, target_resource:target_resource, severity:severity, monitor_service:monitor_service, impacted_scope:impacted_scope, description:description, alert_rule_id:alert_rule_id, action_group:action_group, name:name, custom_headers:custom_headers).value!
      unless response.nil?
        page = response.body
        page.next_method = Proc.new do |next_page_link|
          list_by_subscription_next_async(next_page_link, custom_headers:custom_headers)
        end
        page
      end
    end

    #
    # Get all action rules created in a resource group
    #
    # List all action rules of the subscription, created in given resource group
    # and given input filters
    #
    # @param resource_group_name [String] Resource group name where the resource is
    # created.
    # @param target_resource_group [String] Filter by target resource group name.
    # Default value is select all.
    # @param target_resource_type [String] Filter by target resource type. Default
    # value is select all.
    # @param target_resource [String] Filter by target resource( which is full ARM
    # ID) Default value is select all.
    # @param severity [Severity] Filter by severity.  Default value is select all.
    # Possible values include: 'Sev0', 'Sev1', 'Sev2', 'Sev3', 'Sev4'
    # @param monitor_service [MonitorService] Filter by monitor service which
    # generates the alert instance. Default value is select all. Possible values
    # include: 'Application Insights', 'ActivityLog Administrative', 'ActivityLog
    # Security', 'ActivityLog Recommendation', 'ActivityLog Policy', 'ActivityLog
    # Autoscale', 'Log Analytics', 'Nagios', 'Platform', 'SCOM', 'ServiceHealth',
    # 'SmartDetector', 'VM Insights', 'Zabbix'
    # @param impacted_scope [String] filter by impacted/target scope (provide comma
    # separated list for multiple scopes). The value should be an well constructed
    # ARM id of the scope.
    # @param description [String] filter by alert rule description
    # @param alert_rule_id [String] filter by alert rule id
    # @param action_group [String] filter by action group configured as part of
    # action rule
    # @param name [String] filter by action rule name
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [ActionRulesList] which provide lazy access to pages of the response.
    #
    def list_by_resource_group_as_lazy(resource_group_name, target_resource_group:nil, target_resource_type:nil, target_resource:nil, severity:nil, monitor_service:nil, impacted_scope:nil, description:nil, alert_rule_id:nil, action_group:nil, name:nil, custom_headers:nil)
      response = list_by_resource_group_async(resource_group_name, target_resource_group:target_resource_group, target_resource_type:target_resource_type, target_resource:target_resource, severity:severity, monitor_service:monitor_service, impacted_scope:impacted_scope, description:description, alert_rule_id:alert_rule_id, action_group:action_group, name:name, custom_headers:custom_headers).value!
      unless response.nil?
        page = response.body
        page.next_method = Proc.new do |next_page_link|
          list_by_resource_group_next_async(next_page_link, custom_headers:custom_headers)
        end
        page
      end
    end

  end
end
