=begin
#FinFeedAPI SEC REST API

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

The version of the OpenAPI document: v1
Contact: support@apibricks.io
Generated by: https://openapi-generator.tech
Generator version: 7.13.0

=end

require 'cgi'

module OpenapiClient
  class FilingMetadataApi
    attr_accessor :api_client

    def initialize(api_client = ApiClient.default)
      @api_client = api_client
    end
    # Query SEC filing metadata
    # Retrieves metadata for SEC filings based on various filter criteria with pagination and sorting support.  ### Available Sort Fields  Field Name | Description -----------|------------- AccessionNumber | SEC filing accession number FilingDate | Date when filing was submitted AcceptanceDateTime | Date and time of filing acceptance ReportDate | Date of the report Size | Size of the filing document  ### Date Format All dates must be provided in YYYY-MM-DD format  ### Form Types Form types can be provided as comma-separated values, e.g.: \"10-K,8-K,10-Q\"  :::tip For optimal performance, use date ranges and form types to narrow down your search :::
    # @param [Hash] opts the optional parameters
    # @option opts [Integer] :cik Filter by Central Index Key (CIK)
    # @option opts [String] :ticker Filter by stock ticker symbol
    # @option opts [String] :form_type Filter by form type(s) (e.g., \&quot;10-K\&quot;, \&quot;8-K\&quot;). Multiple values can be comma-separated
    # @option opts [String] :filling_date_start Filter by filling date start (inclusive), format YYYY-MM-DD
    # @option opts [String] :filling_date_end Filter by filling date end (inclusive), format YYYY-MM-DD
    # @option opts [String] :report_date_start Filter by report date start (inclusive), format YYYY-MM-DD
    # @option opts [String] :report_date_end Filter by report date end (inclusive), format YYYY-MM-DD
    # @option opts [String] :items_contain Filter filings where the &#39;Items&#39; field contains the specified text
    # @option opts [Integer] :page_size Number of results per page (default: 50, max: 200)
    # @option opts [Integer] :page_number Page number to retrieve (default: 1)
    # @option opts [DTOFilingSortBy] :sort_by Field to sort results by (default: AccessionNumber)
    # @option opts [String] :sort_order Sort order (asc or desc, default: desc) (default to 'desc')
    # @return [Array<DTOFilingMetadataDto>]
    def v1_filings_get(opts = {})
      data, _status_code, _headers = v1_filings_get_with_http_info(opts)
      data
    end

    # Query SEC filing metadata
    # Retrieves metadata for SEC filings based on various filter criteria with pagination and sorting support.  ### Available Sort Fields  Field Name | Description -----------|------------- AccessionNumber | SEC filing accession number FilingDate | Date when filing was submitted AcceptanceDateTime | Date and time of filing acceptance ReportDate | Date of the report Size | Size of the filing document  ### Date Format All dates must be provided in YYYY-MM-DD format  ### Form Types Form types can be provided as comma-separated values, e.g.: \&quot;10-K,8-K,10-Q\&quot;  :::tip For optimal performance, use date ranges and form types to narrow down your search :::
    # @param [Hash] opts the optional parameters
    # @option opts [Integer] :cik Filter by Central Index Key (CIK)
    # @option opts [String] :ticker Filter by stock ticker symbol
    # @option opts [String] :form_type Filter by form type(s) (e.g., \&quot;10-K\&quot;, \&quot;8-K\&quot;). Multiple values can be comma-separated
    # @option opts [String] :filling_date_start Filter by filling date start (inclusive), format YYYY-MM-DD
    # @option opts [String] :filling_date_end Filter by filling date end (inclusive), format YYYY-MM-DD
    # @option opts [String] :report_date_start Filter by report date start (inclusive), format YYYY-MM-DD
    # @option opts [String] :report_date_end Filter by report date end (inclusive), format YYYY-MM-DD
    # @option opts [String] :items_contain Filter filings where the &#39;Items&#39; field contains the specified text
    # @option opts [Integer] :page_size Number of results per page (default: 50, max: 200)
    # @option opts [Integer] :page_number Page number to retrieve (default: 1)
    # @option opts [DTOFilingSortBy] :sort_by Field to sort results by (default: AccessionNumber)
    # @option opts [String] :sort_order Sort order (asc or desc, default: desc) (default to 'desc')
    # @return [Array<(Array<DTOFilingMetadataDto>, Integer, Hash)>] Array<DTOFilingMetadataDto> data, response status code and response headers
    def v1_filings_get_with_http_info(opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug 'Calling API: FilingMetadataApi.v1_filings_get ...'
      end
      pattern = Regexp.new(/^\d{4}-\d{2}-\d{2}$/)
      if @api_client.config.client_side_validation && !opts[:'filling_date_start'].nil? && opts[:'filling_date_start'] !~ pattern
        fail ArgumentError, "invalid value for 'opts[:\"filling_date_start\"]' when calling FilingMetadataApi.v1_filings_get, must conform to the pattern #{pattern}."
      end

      pattern = Regexp.new(/^\d{4}-\d{2}-\d{2}$/)
      if @api_client.config.client_side_validation && !opts[:'filling_date_end'].nil? && opts[:'filling_date_end'] !~ pattern
        fail ArgumentError, "invalid value for 'opts[:\"filling_date_end\"]' when calling FilingMetadataApi.v1_filings_get, must conform to the pattern #{pattern}."
      end

      pattern = Regexp.new(/^\d{4}-\d{2}-\d{2}$/)
      if @api_client.config.client_side_validation && !opts[:'report_date_start'].nil? && opts[:'report_date_start'] !~ pattern
        fail ArgumentError, "invalid value for 'opts[:\"report_date_start\"]' when calling FilingMetadataApi.v1_filings_get, must conform to the pattern #{pattern}."
      end

      pattern = Regexp.new(/^\d{4}-\d{2}-\d{2}$/)
      if @api_client.config.client_side_validation && !opts[:'report_date_end'].nil? && opts[:'report_date_end'] !~ pattern
        fail ArgumentError, "invalid value for 'opts[:\"report_date_end\"]' when calling FilingMetadataApi.v1_filings_get, must conform to the pattern #{pattern}."
      end

      if @api_client.config.client_side_validation && !opts[:'page_size'].nil? && opts[:'page_size'] > 200
        fail ArgumentError, 'invalid value for "opts[:"page_size"]" when calling FilingMetadataApi.v1_filings_get, must be smaller than or equal to 200.'
      end

      if @api_client.config.client_side_validation && !opts[:'page_size'].nil? && opts[:'page_size'] < 1
        fail ArgumentError, 'invalid value for "opts[:"page_size"]" when calling FilingMetadataApi.v1_filings_get, must be greater than or equal to 1.'
      end

      if @api_client.config.client_side_validation && !opts[:'page_number'].nil? && opts[:'page_number'] > 2147483647
        fail ArgumentError, 'invalid value for "opts[:"page_number"]" when calling FilingMetadataApi.v1_filings_get, must be smaller than or equal to 2147483647.'
      end

      if @api_client.config.client_side_validation && !opts[:'page_number'].nil? && opts[:'page_number'] < 1
        fail ArgumentError, 'invalid value for "opts[:"page_number"]" when calling FilingMetadataApi.v1_filings_get, must be greater than or equal to 1.'
      end

      pattern = Regexp.new(/^(asc|desc)$/)
      if @api_client.config.client_side_validation && !opts[:'sort_order'].nil? && opts[:'sort_order'] !~ pattern
        fail ArgumentError, "invalid value for 'opts[:\"sort_order\"]' when calling FilingMetadataApi.v1_filings_get, must conform to the pattern #{pattern}."
      end

      # resource path
      local_var_path = '/v1/filings'

      # query parameters
      query_params = opts[:query_params] || {}
      query_params[:'cik'] = opts[:'cik'] if !opts[:'cik'].nil?
      query_params[:'ticker'] = opts[:'ticker'] if !opts[:'ticker'].nil?
      query_params[:'form_type'] = opts[:'form_type'] if !opts[:'form_type'].nil?
      query_params[:'filling_date_start'] = opts[:'filling_date_start'] if !opts[:'filling_date_start'].nil?
      query_params[:'filling_date_end'] = opts[:'filling_date_end'] if !opts[:'filling_date_end'].nil?
      query_params[:'report_date_start'] = opts[:'report_date_start'] if !opts[:'report_date_start'].nil?
      query_params[:'report_date_end'] = opts[:'report_date_end'] if !opts[:'report_date_end'].nil?
      query_params[:'items_contain'] = opts[:'items_contain'] if !opts[:'items_contain'].nil?
      query_params[:'page_size'] = opts[:'page_size'] if !opts[:'page_size'].nil?
      query_params[:'page_number'] = opts[:'page_number'] if !opts[:'page_number'].nil?
      query_params[:'sort_by'] = opts[:'sort_by'] if !opts[:'sort_by'].nil?
      query_params[:'sort_order'] = opts[:'sort_order'] if !opts[:'sort_order'].nil?

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

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

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

      # return_type
      return_type = opts[:debug_return_type] || 'Array<DTOFilingMetadataDto>'

      # auth_names
      auth_names = opts[:debug_auth_names] || ['APIKey', 'JWT']

      new_options = opts.merge(
        :operation => :"FilingMetadataApi.v1_filings_get",
        :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: FilingMetadataApi#v1_filings_get\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
      end
      return data, status_code, headers
    end
  end
end
