# 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::V2018_05_05
  #
  # AlertsManagement Client
  #
  class Alerts
    include MsRestAzure

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

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

    #
    # List all existing alerts, where the results can be filtered on the basis of
    # multiple parameters (e.g. time range). The results can then be sorted on the
    # basis specific fields, with the default being lastModifiedDateTime.
    #
    # @param target_resource [String] Filter by target resource( which is full ARM
    # ID) Default value is select all.
    # @param target_resource_type [String] Filter by target resource type. Default
    # value is select all.
    # @param target_resource_group [String] Filter by target resource group name.
    # Default value is select all.
    # @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 monitor_condition [MonitorCondition] Filter by monitor condition which
    # is either 'Fired' or 'Resolved'. Default value is to select all. Possible
    # values include: 'Fired', 'Resolved'
    # @param severity [Severity] Filter by severity.  Default value is select all.
    # Possible values include: 'Sev0', 'Sev1', 'Sev2', 'Sev3', 'Sev4'
    # @param alert_state [AlertState] Filter by state of the alert instance.
    # Default value is to select all. Possible values include: 'New',
    # 'Acknowledged', 'Closed'
    # @param alert_rule [String] Filter by specific alert rule.  Default value is
    # to select all.
    # @param smart_group_id [String] Filter the alerts list by the Smart Group Id.
    # Default value is none.
    # @param include_context [Boolean] Include context which has contextual data
    # specific to the monitor service. Default value is false'
    # @param include_egress_config [Boolean] Include egress config which would be
    # used for displaying the content in portal.  Default value is 'false'.
    # @param page_count [Integer] Determines number of alerts returned per page in
    # response. Permissible value is between 1 to 250. When the "includeContent"
    # filter is selected, maximum value allowed is 25. Default value is 25.
    # @param sort_by [AlertsSortByFields] Sort the query results by input field,
    # Default value is 'lastModifiedDateTime'. Possible values include: 'name',
    # 'severity', 'alertState', 'monitorCondition', 'targetResource',
    # 'targetResourceName', 'targetResourceGroup', 'targetResourceType',
    # 'startDateTime', 'lastModifiedDateTime'
    # @param sort_order [Enum] Sort the query results order in either ascending or
    # descending.  Default value is 'desc' for time fields and 'asc' for others.
    # Possible values include: 'asc', 'desc'
    # @param select [String] This filter allows to selection of the fields(comma
    # separated) which would  be part of the essential section. This would allow to
    # project only the  required fields rather than getting entire content.
    # Default is to fetch all the fields in the essentials section.
    # @param time_range [TimeRange] Filter by time range by below listed values.
    # Default value is 1 day. Possible values include: '1h', '1d', '7d', '30d'
    # @param custom_time_range [String] Filter by custom time range in the format
    # <start-time>/<end-time>  where time is in (ISO-8601 format)'. Permissible
    # values is within 30 days from  query time. Either timeRange or
    # customTimeRange could be used but not both. Default is none.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Array<Alert>] operation results.
    #
    def get_all(target_resource:nil, target_resource_type:nil, target_resource_group:nil, monitor_service:nil, monitor_condition:nil, severity:nil, alert_state:nil, alert_rule:nil, smart_group_id:nil, include_context:nil, include_egress_config:nil, page_count:nil, sort_by:nil, sort_order:nil, select:nil, time_range:nil, custom_time_range:nil, custom_headers:nil)
      first_page = get_all_as_lazy(target_resource:target_resource, target_resource_type:target_resource_type, target_resource_group:target_resource_group, monitor_service:monitor_service, monitor_condition:monitor_condition, severity:severity, alert_state:alert_state, alert_rule:alert_rule, smart_group_id:smart_group_id, include_context:include_context, include_egress_config:include_egress_config, page_count:page_count, sort_by:sort_by, sort_order:sort_order, select:select, time_range:time_range, custom_time_range:custom_time_range, custom_headers:custom_headers)
      first_page.get_all_items
    end

    #
    # List all existing alerts, where the results can be filtered on the basis of
    # multiple parameters (e.g. time range). The results can then be sorted on the
    # basis specific fields, with the default being lastModifiedDateTime.
    #
    # @param target_resource [String] Filter by target resource( which is full ARM
    # ID) Default value is select all.
    # @param target_resource_type [String] Filter by target resource type. Default
    # value is select all.
    # @param target_resource_group [String] Filter by target resource group name.
    # Default value is select all.
    # @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 monitor_condition [MonitorCondition] Filter by monitor condition which
    # is either 'Fired' or 'Resolved'. Default value is to select all. Possible
    # values include: 'Fired', 'Resolved'
    # @param severity [Severity] Filter by severity.  Default value is select all.
    # Possible values include: 'Sev0', 'Sev1', 'Sev2', 'Sev3', 'Sev4'
    # @param alert_state [AlertState] Filter by state of the alert instance.
    # Default value is to select all. Possible values include: 'New',
    # 'Acknowledged', 'Closed'
    # @param alert_rule [String] Filter by specific alert rule.  Default value is
    # to select all.
    # @param smart_group_id [String] Filter the alerts list by the Smart Group Id.
    # Default value is none.
    # @param include_context [Boolean] Include context which has contextual data
    # specific to the monitor service. Default value is false'
    # @param include_egress_config [Boolean] Include egress config which would be
    # used for displaying the content in portal.  Default value is 'false'.
    # @param page_count [Integer] Determines number of alerts returned per page in
    # response. Permissible value is between 1 to 250. When the "includeContent"
    # filter is selected, maximum value allowed is 25. Default value is 25.
    # @param sort_by [AlertsSortByFields] Sort the query results by input field,
    # Default value is 'lastModifiedDateTime'. Possible values include: 'name',
    # 'severity', 'alertState', 'monitorCondition', 'targetResource',
    # 'targetResourceName', 'targetResourceGroup', 'targetResourceType',
    # 'startDateTime', 'lastModifiedDateTime'
    # @param sort_order [Enum] Sort the query results order in either ascending or
    # descending.  Default value is 'desc' for time fields and 'asc' for others.
    # Possible values include: 'asc', 'desc'
    # @param select [String] This filter allows to selection of the fields(comma
    # separated) which would  be part of the essential section. This would allow to
    # project only the  required fields rather than getting entire content.
    # Default is to fetch all the fields in the essentials section.
    # @param time_range [TimeRange] Filter by time range by below listed values.
    # Default value is 1 day. Possible values include: '1h', '1d', '7d', '30d'
    # @param custom_time_range [String] Filter by custom time range in the format
    # <start-time>/<end-time>  where time is in (ISO-8601 format)'. Permissible
    # values is within 30 days from  query time. Either timeRange or
    # customTimeRange could be used but not both. Default is none.
    # @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_all_with_http_info(target_resource:nil, target_resource_type:nil, target_resource_group:nil, monitor_service:nil, monitor_condition:nil, severity:nil, alert_state:nil, alert_rule:nil, smart_group_id:nil, include_context:nil, include_egress_config:nil, page_count:nil, sort_by:nil, sort_order:nil, select:nil, time_range:nil, custom_time_range:nil, custom_headers:nil)
      get_all_async(target_resource:target_resource, target_resource_type:target_resource_type, target_resource_group:target_resource_group, monitor_service:monitor_service, monitor_condition:monitor_condition, severity:severity, alert_state:alert_state, alert_rule:alert_rule, smart_group_id:smart_group_id, include_context:include_context, include_egress_config:include_egress_config, page_count:page_count, sort_by:sort_by, sort_order:sort_order, select:select, time_range:time_range, custom_time_range:custom_time_range, custom_headers:custom_headers).value!
    end

    #
    # List all existing alerts, where the results can be filtered on the basis of
    # multiple parameters (e.g. time range). The results can then be sorted on the
    # basis specific fields, with the default being lastModifiedDateTime.
    #
    # @param target_resource [String] Filter by target resource( which is full ARM
    # ID) Default value is select all.
    # @param target_resource_type [String] Filter by target resource type. Default
    # value is select all.
    # @param target_resource_group [String] Filter by target resource group name.
    # Default value is select all.
    # @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 monitor_condition [MonitorCondition] Filter by monitor condition which
    # is either 'Fired' or 'Resolved'. Default value is to select all. Possible
    # values include: 'Fired', 'Resolved'
    # @param severity [Severity] Filter by severity.  Default value is select all.
    # Possible values include: 'Sev0', 'Sev1', 'Sev2', 'Sev3', 'Sev4'
    # @param alert_state [AlertState] Filter by state of the alert instance.
    # Default value is to select all. Possible values include: 'New',
    # 'Acknowledged', 'Closed'
    # @param alert_rule [String] Filter by specific alert rule.  Default value is
    # to select all.
    # @param smart_group_id [String] Filter the alerts list by the Smart Group Id.
    # Default value is none.
    # @param include_context [Boolean] Include context which has contextual data
    # specific to the monitor service. Default value is false'
    # @param include_egress_config [Boolean] Include egress config which would be
    # used for displaying the content in portal.  Default value is 'false'.
    # @param page_count [Integer] Determines number of alerts returned per page in
    # response. Permissible value is between 1 to 250. When the "includeContent"
    # filter is selected, maximum value allowed is 25. Default value is 25.
    # @param sort_by [AlertsSortByFields] Sort the query results by input field,
    # Default value is 'lastModifiedDateTime'. Possible values include: 'name',
    # 'severity', 'alertState', 'monitorCondition', 'targetResource',
    # 'targetResourceName', 'targetResourceGroup', 'targetResourceType',
    # 'startDateTime', 'lastModifiedDateTime'
    # @param sort_order [Enum] Sort the query results order in either ascending or
    # descending.  Default value is 'desc' for time fields and 'asc' for others.
    # Possible values include: 'asc', 'desc'
    # @param select [String] This filter allows to selection of the fields(comma
    # separated) which would  be part of the essential section. This would allow to
    # project only the  required fields rather than getting entire content.
    # Default is to fetch all the fields in the essentials section.
    # @param time_range [TimeRange] Filter by time range by below listed values.
    # Default value is 1 day. Possible values include: '1h', '1d', '7d', '30d'
    # @param custom_time_range [String] Filter by custom time range in the format
    # <start-time>/<end-time>  where time is in (ISO-8601 format)'. Permissible
    # values is within 30 days from  query time. Either timeRange or
    # customTimeRange could be used but not both. Default is none.
    # @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_all_async(target_resource:nil, target_resource_type:nil, target_resource_group:nil, monitor_service:nil, monitor_condition:nil, severity:nil, alert_state:nil, alert_rule:nil, smart_group_id:nil, include_context:nil, include_egress_config:nil, page_count:nil, sort_by:nil, sort_order:nil, select:nil, time_range:nil, custom_time_range:nil, custom_headers:nil)
      fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
      @client.api_version = '2018-05-05'


      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/alerts'

      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: {'targetResource' => target_resource,'targetResourceType' => target_resource_type,'targetResourceGroup' => target_resource_group,'monitorService' => monitor_service,'monitorCondition' => monitor_condition,'severity' => severity,'alertState' => alert_state,'alertRule' => alert_rule,'smartGroupId' => smart_group_id,'includeContext' => include_context,'includeEgressConfig' => include_egress_config,'pageCount' => page_count,'sortBy' => sort_by,'sortOrder' => sort_order,'select' => select,'timeRange' => time_range,'customTimeRange' => custom_time_range,'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::V2018_05_05::Models::AlertsList.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 a specific alert.
    #
    # Get information related to a specific alert
    #
    # @param alert_id [String] Unique ID of an alert instance.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Alert] operation results.
    #
    def get_by_id(alert_id, custom_headers:nil)
      response = get_by_id_async(alert_id, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Get a specific alert.
    #
    # Get information related to a specific alert
    #
    # @param alert_id [String] Unique ID of an alert instance.
    # @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_id_with_http_info(alert_id, custom_headers:nil)
      get_by_id_async(alert_id, custom_headers:custom_headers).value!
    end

    #
    # Get a specific alert.
    #
    # Get information related to a specific alert
    #
    # @param alert_id [String] Unique ID of an alert instance.
    # @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_id_async(alert_id, custom_headers:nil)
      fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
      fail ArgumentError, 'alert_id is nil' if alert_id.nil?
      @client.api_version = '2018-05-05'


      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/alerts/{alertId}'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'subscriptionId' => @client.subscription_id,'alertId' => alert_id},
          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::V2018_05_05::Models::Alert.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

    #
    # Change the state of an alert.
    #
    # @param alert_id [String] Unique ID of an alert instance.
    # @param new_state [AlertState] New state of the alert. Possible values
    # include: 'New', 'Acknowledged', 'Closed'
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Alert] operation results.
    #
    def change_state(alert_id, new_state, custom_headers:nil)
      response = change_state_async(alert_id, new_state, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Change the state of an alert.
    #
    # @param alert_id [String] Unique ID of an alert instance.
    # @param new_state [AlertState] New state of the alert. Possible values
    # include: 'New', 'Acknowledged', 'Closed'
    # @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 change_state_with_http_info(alert_id, new_state, custom_headers:nil)
      change_state_async(alert_id, new_state, custom_headers:custom_headers).value!
    end

    #
    # Change the state of an alert.
    #
    # @param alert_id [String] Unique ID of an alert instance.
    # @param new_state [AlertState] New state of the alert. Possible values
    # include: 'New', 'Acknowledged', 'Closed'
    # @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 change_state_async(alert_id, new_state, custom_headers:nil)
      fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
      fail ArgumentError, 'alert_id is nil' if alert_id.nil?
      @client.api_version = '2018-05-05'
      fail ArgumentError, 'new_state is nil' if new_state.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 = 'subscriptions/{subscriptionId}/providers/Microsoft.AlertsManagement/alerts/{alertId}/changestate'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'subscriptionId' => @client.subscription_id,'alertId' => alert_id},
          query_params: {'api-version' => @client.api_version,'newState' => new_state},
          headers: request_headers.merge(custom_headers || {}),
          base_url: request_url
      }
      promise = @client.make_request_async(:post, 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::V2018_05_05::Models::Alert.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 the history of an alert, which captures any monitor condition changes
    # (Fired/Resolved) and alert state changes (New/Acknowledged/Closed).
    #
    # @param alert_id [String] Unique ID of an alert instance.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [AlertModification] operation results.
    #
    def get_history(alert_id, custom_headers:nil)
      response = get_history_async(alert_id, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Get the history of an alert, which captures any monitor condition changes
    # (Fired/Resolved) and alert state changes (New/Acknowledged/Closed).
    #
    # @param alert_id [String] Unique ID of an alert instance.
    # @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_history_with_http_info(alert_id, custom_headers:nil)
      get_history_async(alert_id, custom_headers:custom_headers).value!
    end

    #
    # Get the history of an alert, which captures any monitor condition changes
    # (Fired/Resolved) and alert state changes (New/Acknowledged/Closed).
    #
    # @param alert_id [String] Unique ID of an alert instance.
    # @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_history_async(alert_id, custom_headers:nil)
      fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
      fail ArgumentError, 'alert_id is nil' if alert_id.nil?
      @client.api_version = '2018-05-05'


      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/alerts/{alertId}/history'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'subscriptionId' => @client.subscription_id,'alertId' => alert_id},
          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::V2018_05_05::Models::AlertModification.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 a summarized count of your alerts grouped by various parameters (e.g.
    # grouping by 'Severity' returns the count of alerts for each severity).
    #
    # @param groupby [AlertsSummaryGroupByFields] This parameter allows the result
    # set to be grouped by input fields. For example, groupby=severity,alertstate.
    # Possible values include: 'severity', 'alertState', 'monitorCondition',
    # 'monitorService', 'signalType', 'alertRule'
    # @param include_smart_groups_count [Boolean] Include count of the SmartGroups
    # as part of the summary. Default value is 'false'.
    # @param target_resource [String] Filter by target resource( which is full ARM
    # ID) Default value is select all.
    # @param target_resource_type [String] Filter by target resource type. Default
    # value is select all.
    # @param target_resource_group [String] Filter by target resource group name.
    # Default value is select all.
    # @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 monitor_condition [MonitorCondition] Filter by monitor condition which
    # is either 'Fired' or 'Resolved'. Default value is to select all. Possible
    # values include: 'Fired', 'Resolved'
    # @param severity [Severity] Filter by severity.  Default value is select all.
    # Possible values include: 'Sev0', 'Sev1', 'Sev2', 'Sev3', 'Sev4'
    # @param alert_state [AlertState] Filter by state of the alert instance.
    # Default value is to select all. Possible values include: 'New',
    # 'Acknowledged', 'Closed'
    # @param alert_rule [String] Filter by specific alert rule.  Default value is
    # to select all.
    # @param time_range [TimeRange] Filter by time range by below listed values.
    # Default value is 1 day. Possible values include: '1h', '1d', '7d', '30d'
    # @param custom_time_range [String] Filter by custom time range in the format
    # <start-time>/<end-time>  where time is in (ISO-8601 format)'. Permissible
    # values is within 30 days from  query time. Either timeRange or
    # customTimeRange could be used but not both. Default is none.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [AlertsSummary] operation results.
    #
    def get_summary(groupby, include_smart_groups_count:nil, target_resource:nil, target_resource_type:nil, target_resource_group:nil, monitor_service:nil, monitor_condition:nil, severity:nil, alert_state:nil, alert_rule:nil, time_range:nil, custom_time_range:nil, custom_headers:nil)
      response = get_summary_async(groupby, include_smart_groups_count:include_smart_groups_count, target_resource:target_resource, target_resource_type:target_resource_type, target_resource_group:target_resource_group, monitor_service:monitor_service, monitor_condition:monitor_condition, severity:severity, alert_state:alert_state, alert_rule:alert_rule, time_range:time_range, custom_time_range:custom_time_range, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Get a summarized count of your alerts grouped by various parameters (e.g.
    # grouping by 'Severity' returns the count of alerts for each severity).
    #
    # @param groupby [AlertsSummaryGroupByFields] This parameter allows the result
    # set to be grouped by input fields. For example, groupby=severity,alertstate.
    # Possible values include: 'severity', 'alertState', 'monitorCondition',
    # 'monitorService', 'signalType', 'alertRule'
    # @param include_smart_groups_count [Boolean] Include count of the SmartGroups
    # as part of the summary. Default value is 'false'.
    # @param target_resource [String] Filter by target resource( which is full ARM
    # ID) Default value is select all.
    # @param target_resource_type [String] Filter by target resource type. Default
    # value is select all.
    # @param target_resource_group [String] Filter by target resource group name.
    # Default value is select all.
    # @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 monitor_condition [MonitorCondition] Filter by monitor condition which
    # is either 'Fired' or 'Resolved'. Default value is to select all. Possible
    # values include: 'Fired', 'Resolved'
    # @param severity [Severity] Filter by severity.  Default value is select all.
    # Possible values include: 'Sev0', 'Sev1', 'Sev2', 'Sev3', 'Sev4'
    # @param alert_state [AlertState] Filter by state of the alert instance.
    # Default value is to select all. Possible values include: 'New',
    # 'Acknowledged', 'Closed'
    # @param alert_rule [String] Filter by specific alert rule.  Default value is
    # to select all.
    # @param time_range [TimeRange] Filter by time range by below listed values.
    # Default value is 1 day. Possible values include: '1h', '1d', '7d', '30d'
    # @param custom_time_range [String] Filter by custom time range in the format
    # <start-time>/<end-time>  where time is in (ISO-8601 format)'. Permissible
    # values is within 30 days from  query time. Either timeRange or
    # customTimeRange could be used but not both. Default is none.
    # @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_summary_with_http_info(groupby, include_smart_groups_count:nil, target_resource:nil, target_resource_type:nil, target_resource_group:nil, monitor_service:nil, monitor_condition:nil, severity:nil, alert_state:nil, alert_rule:nil, time_range:nil, custom_time_range:nil, custom_headers:nil)
      get_summary_async(groupby, include_smart_groups_count:include_smart_groups_count, target_resource:target_resource, target_resource_type:target_resource_type, target_resource_group:target_resource_group, monitor_service:monitor_service, monitor_condition:monitor_condition, severity:severity, alert_state:alert_state, alert_rule:alert_rule, time_range:time_range, custom_time_range:custom_time_range, custom_headers:custom_headers).value!
    end

    #
    # Get a summarized count of your alerts grouped by various parameters (e.g.
    # grouping by 'Severity' returns the count of alerts for each severity).
    #
    # @param groupby [AlertsSummaryGroupByFields] This parameter allows the result
    # set to be grouped by input fields. For example, groupby=severity,alertstate.
    # Possible values include: 'severity', 'alertState', 'monitorCondition',
    # 'monitorService', 'signalType', 'alertRule'
    # @param include_smart_groups_count [Boolean] Include count of the SmartGroups
    # as part of the summary. Default value is 'false'.
    # @param target_resource [String] Filter by target resource( which is full ARM
    # ID) Default value is select all.
    # @param target_resource_type [String] Filter by target resource type. Default
    # value is select all.
    # @param target_resource_group [String] Filter by target resource group name.
    # Default value is select all.
    # @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 monitor_condition [MonitorCondition] Filter by monitor condition which
    # is either 'Fired' or 'Resolved'. Default value is to select all. Possible
    # values include: 'Fired', 'Resolved'
    # @param severity [Severity] Filter by severity.  Default value is select all.
    # Possible values include: 'Sev0', 'Sev1', 'Sev2', 'Sev3', 'Sev4'
    # @param alert_state [AlertState] Filter by state of the alert instance.
    # Default value is to select all. Possible values include: 'New',
    # 'Acknowledged', 'Closed'
    # @param alert_rule [String] Filter by specific alert rule.  Default value is
    # to select all.
    # @param time_range [TimeRange] Filter by time range by below listed values.
    # Default value is 1 day. Possible values include: '1h', '1d', '7d', '30d'
    # @param custom_time_range [String] Filter by custom time range in the format
    # <start-time>/<end-time>  where time is in (ISO-8601 format)'. Permissible
    # values is within 30 days from  query time. Either timeRange or
    # customTimeRange could be used but not both. Default is none.
    # @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_summary_async(groupby, include_smart_groups_count:nil, target_resource:nil, target_resource_type:nil, target_resource_group:nil, monitor_service:nil, monitor_condition:nil, severity:nil, alert_state:nil, alert_rule:nil, time_range:nil, custom_time_range:nil, custom_headers:nil)
      fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
      fail ArgumentError, 'groupby is nil' if groupby.nil?
      @client.api_version = '2018-05-05'


      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/alertsSummary'

      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: {'groupby' => groupby,'includeSmartGroupsCount' => include_smart_groups_count,'targetResource' => target_resource,'targetResourceType' => target_resource_type,'targetResourceGroup' => target_resource_group,'monitorService' => monitor_service,'monitorCondition' => monitor_condition,'severity' => severity,'alertState' => alert_state,'alertRule' => alert_rule,'timeRange' => time_range,'customTimeRange' => custom_time_range,'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::V2018_05_05::Models::AlertsSummary.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

    #
    # List all existing alerts, where the results can be filtered on the basis of
    # multiple parameters (e.g. time range). The results can then be sorted on the
    # basis specific fields, with the default being lastModifiedDateTime.
    #
    # @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 [AlertsList] operation results.
    #
    def get_all_next(next_page_link, custom_headers:nil)
      response = get_all_next_async(next_page_link, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # List all existing alerts, where the results can be filtered on the basis of
    # multiple parameters (e.g. time range). The results can then be sorted on the
    # basis specific fields, with the default being lastModifiedDateTime.
    #
    # @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 get_all_next_with_http_info(next_page_link, custom_headers:nil)
      get_all_next_async(next_page_link, custom_headers:custom_headers).value!
    end

    #
    # List all existing alerts, where the results can be filtered on the basis of
    # multiple parameters (e.g. time range). The results can then be sorted on the
    # basis specific fields, with the default being lastModifiedDateTime.
    #
    # @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 get_all_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::V2018_05_05::Models::AlertsList.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

    #
    # List all existing alerts, where the results can be filtered on the basis of
    # multiple parameters (e.g. time range). The results can then be sorted on the
    # basis specific fields, with the default being lastModifiedDateTime.
    #
    # @param target_resource [String] Filter by target resource( which is full ARM
    # ID) Default value is select all.
    # @param target_resource_type [String] Filter by target resource type. Default
    # value is select all.
    # @param target_resource_group [String] Filter by target resource group name.
    # Default value is select all.
    # @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 monitor_condition [MonitorCondition] Filter by monitor condition which
    # is either 'Fired' or 'Resolved'. Default value is to select all. Possible
    # values include: 'Fired', 'Resolved'
    # @param severity [Severity] Filter by severity.  Default value is select all.
    # Possible values include: 'Sev0', 'Sev1', 'Sev2', 'Sev3', 'Sev4'
    # @param alert_state [AlertState] Filter by state of the alert instance.
    # Default value is to select all. Possible values include: 'New',
    # 'Acknowledged', 'Closed'
    # @param alert_rule [String] Filter by specific alert rule.  Default value is
    # to select all.
    # @param smart_group_id [String] Filter the alerts list by the Smart Group Id.
    # Default value is none.
    # @param include_context [Boolean] Include context which has contextual data
    # specific to the monitor service. Default value is false'
    # @param include_egress_config [Boolean] Include egress config which would be
    # used for displaying the content in portal.  Default value is 'false'.
    # @param page_count [Integer] Determines number of alerts returned per page in
    # response. Permissible value is between 1 to 250. When the "includeContent"
    # filter is selected, maximum value allowed is 25. Default value is 25.
    # @param sort_by [AlertsSortByFields] Sort the query results by input field,
    # Default value is 'lastModifiedDateTime'. Possible values include: 'name',
    # 'severity', 'alertState', 'monitorCondition', 'targetResource',
    # 'targetResourceName', 'targetResourceGroup', 'targetResourceType',
    # 'startDateTime', 'lastModifiedDateTime'
    # @param sort_order [Enum] Sort the query results order in either ascending or
    # descending.  Default value is 'desc' for time fields and 'asc' for others.
    # Possible values include: 'asc', 'desc'
    # @param select [String] This filter allows to selection of the fields(comma
    # separated) which would  be part of the essential section. This would allow to
    # project only the  required fields rather than getting entire content.
    # Default is to fetch all the fields in the essentials section.
    # @param time_range [TimeRange] Filter by time range by below listed values.
    # Default value is 1 day. Possible values include: '1h', '1d', '7d', '30d'
    # @param custom_time_range [String] Filter by custom time range in the format
    # <start-time>/<end-time>  where time is in (ISO-8601 format)'. Permissible
    # values is within 30 days from  query time. Either timeRange or
    # customTimeRange could be used but not both. Default is none.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [AlertsList] which provide lazy access to pages of the response.
    #
    def get_all_as_lazy(target_resource:nil, target_resource_type:nil, target_resource_group:nil, monitor_service:nil, monitor_condition:nil, severity:nil, alert_state:nil, alert_rule:nil, smart_group_id:nil, include_context:nil, include_egress_config:nil, page_count:nil, sort_by:nil, sort_order:nil, select:nil, time_range:nil, custom_time_range:nil, custom_headers:nil)
      response = get_all_async(target_resource:target_resource, target_resource_type:target_resource_type, target_resource_group:target_resource_group, monitor_service:monitor_service, monitor_condition:monitor_condition, severity:severity, alert_state:alert_state, alert_rule:alert_rule, smart_group_id:smart_group_id, include_context:include_context, include_egress_config:include_egress_config, page_count:page_count, sort_by:sort_by, sort_order:sort_order, select:select, time_range:time_range, custom_time_range:custom_time_range, custom_headers:custom_headers).value!
      unless response.nil?
        page = response.body
        page.next_method = Proc.new do |next_page_link|
          get_all_next_async(next_page_link, custom_headers:custom_headers)
        end
        page
      end
    end

  end
end
