=begin
#Marketing Emails

#No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

The version of the OpenAPI document: v3

Generated by: https://openapi-generator.tech
OpenAPI Generator version: 6.2.1

=end

require 'cgi'

module Hubspot
  module Marketing
    module Emails
      class StatisticsApi
        attr_accessor :api_client

        def initialize(api_client = ApiClient.default)
          @api_client = api_client
        end
        # Get aggregated statistics.
        # Use this endpoint to get aggregated statistics of emails sent in a specified time span. It also returns the list of emails that were sent during the time span.
        # @param [Hash] opts the optional parameters
        # @option opts [String] :start_timestamp The start timestamp of the time span, in ISO8601 representation.
        # @option opts [String] :end_timestamp The end timestamp of the time span, in ISO8601 representation.
        # @option opts [Array<Integer>] :email_ids Filter by email IDs. Only include statistics of emails with these IDs.
        # @option opts [String] :property Specifies which email properties should be returned. All properties will be returned by default.
        # @return [AggregateEmailStatistics]
        def get_emails_list(opts = {})
          data, _status_code, _headers = get_emails_list_with_http_info(opts)
          data
        end

        # Get aggregated statistics.
        # Use this endpoint to get aggregated statistics of emails sent in a specified time span. It also returns the list of emails that were sent during the time span.
        # @param [Hash] opts the optional parameters
        # @option opts [String] :start_timestamp The start timestamp of the time span, in ISO8601 representation.
        # @option opts [String] :end_timestamp The end timestamp of the time span, in ISO8601 representation.
        # @option opts [Array<Integer>] :email_ids Filter by email IDs. Only include statistics of emails with these IDs.
        # @option opts [String] :property Specifies which email properties should be returned. All properties will be returned by default.
        # @return [Array<(AggregateEmailStatistics, Integer, Hash)>] AggregateEmailStatistics data, response status code and response headers
        def get_emails_list_with_http_info(opts = {})
          if @api_client.config.debugging
            @api_client.config.logger.debug 'Calling API: StatisticsApi.get_emails_list ...'
          end
          # resource path
          local_var_path = '/marketing/v3/emails/statistics/list'

          # query parameters
          query_params = opts[:query_params] || {}
          query_params[:'startTimestamp'] = opts[:'start_timestamp'] if !opts[:'start_timestamp'].nil?
          query_params[:'endTimestamp'] = opts[:'end_timestamp'] if !opts[:'end_timestamp'].nil?
          query_params[:'emailIds'] = @api_client.build_collection_param(opts[:'email_ids'], :multi) if !opts[:'email_ids'].nil?
          query_params[:'property'] = opts[:'property'] if !opts[:'property'].nil?

          # header parameters
          header_params = opts[:header_params] || {}
          # HTTP header 'Accept' (if needed)
          header_params['Accept'] = @api_client.select_header_accept(['application/json', '*/*'])

          # form parameters
          form_params = opts[:form_params] || {}

          # http body (model)
          post_body = opts[:debug_body]

          # return_type
          return_type = opts[:debug_return_type] || 'AggregateEmailStatistics'

          # auth_names
          auth_names = opts[:debug_auth_names] || ['oauth2']

          new_options = opts.merge(
            :operation => :"StatisticsApi.get_emails_list",
            :header_params => header_params,
            :query_params => query_params,
            :form_params => form_params,
            :body => post_body,
            :auth_names => auth_names,
            :return_type => return_type
          )

          data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
          if @api_client.config.debugging
            @api_client.config.logger.debug "API called: StatisticsApi#get_emails_list\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
          end
          return data, status_code, headers
        end

        # Get aggregated statistic intervals.
        # Get aggregated statistics in intervals for a specified time span. Each interval contains aggregated statistics of the emails that were sent in that time.
        # @param [Hash] opts the optional parameters
        # @option opts [String] :interval The interval to aggregate statistics for.
        # @option opts [String] :start_timestamp The start timestamp of the time span, in ISO8601 representation.
        # @option opts [String] :end_timestamp The end timestamp of the time span, in ISO8601 representation.
        # @option opts [Array<Integer>] :email_ids Filter by email IDs. Only include statistics of emails with these IDs.
        # @return [CollectionResponseWithTotalEmailStatisticIntervalNoPaging]
        def get_histogram(opts = {})
          data, _status_code, _headers = get_histogram_with_http_info(opts)
          data
        end

        # Get aggregated statistic intervals.
        # Get aggregated statistics in intervals for a specified time span. Each interval contains aggregated statistics of the emails that were sent in that time.
        # @param [Hash] opts the optional parameters
        # @option opts [String] :interval The interval to aggregate statistics for.
        # @option opts [String] :start_timestamp The start timestamp of the time span, in ISO8601 representation.
        # @option opts [String] :end_timestamp The end timestamp of the time span, in ISO8601 representation.
        # @option opts [Array<Integer>] :email_ids Filter by email IDs. Only include statistics of emails with these IDs.
        # @return [Array<(CollectionResponseWithTotalEmailStatisticIntervalNoPaging, Integer, Hash)>] CollectionResponseWithTotalEmailStatisticIntervalNoPaging data, response status code and response headers
        def get_histogram_with_http_info(opts = {})
          if @api_client.config.debugging
            @api_client.config.logger.debug 'Calling API: StatisticsApi.get_histogram ...'
          end
          allowable_values = ["YEAR", "QUARTER", "MONTH", "WEEK", "DAY", "HOUR", "QUARTER_HOUR", "MINUTE", "SECOND"]
          if @api_client.config.client_side_validation && opts[:'interval'] && !allowable_values.include?(opts[:'interval'])
            fail ArgumentError, "invalid value for \"interval\", must be one of #{allowable_values}"
          end
          # resource path
          local_var_path = '/marketing/v3/emails/statistics/histogram'

          # query parameters
          query_params = opts[:query_params] || {}
          query_params[:'interval'] = opts[:'interval'] if !opts[:'interval'].nil?
          query_params[:'startTimestamp'] = opts[:'start_timestamp'] if !opts[:'start_timestamp'].nil?
          query_params[:'endTimestamp'] = opts[:'end_timestamp'] if !opts[:'end_timestamp'].nil?
          query_params[:'emailIds'] = @api_client.build_collection_param(opts[:'email_ids'], :multi) if !opts[:'email_ids'].nil?

          # header parameters
          header_params = opts[:header_params] || {}
          # HTTP header 'Accept' (if needed)
          header_params['Accept'] = @api_client.select_header_accept(['application/json', '*/*'])

          # form parameters
          form_params = opts[:form_params] || {}

          # http body (model)
          post_body = opts[:debug_body]

          # return_type
          return_type = opts[:debug_return_type] || 'CollectionResponseWithTotalEmailStatisticIntervalNoPaging'

          # auth_names
          auth_names = opts[:debug_auth_names] || ['oauth2']

          new_options = opts.merge(
            :operation => :"StatisticsApi.get_histogram",
            :header_params => header_params,
            :query_params => query_params,
            :form_params => form_params,
            :body => post_body,
            :auth_names => auth_names,
            :return_type => return_type
          )

          data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
          if @api_client.config.debugging
            @api_client.config.logger.debug "API called: StatisticsApi#get_histogram\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
          end
          return data, status_code, headers
        end
      end
    end
  end
end
