=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 FileDownloadApi
    attr_accessor :api_client

    def initialize(api_client = ApiClient.default)
      @api_client = api_client
    end
    # Download file from SEC EDGAR archive
    # Downloads a specific file from the SEC EDGAR archive using the accession number and filename. The file is streamed directly from the SEC servers to the client.  ### Accession Number Format Accession numbers must be in the format: 0000000000-00-000000 (10 digits, dash, 2 digits, dash, 6 digits)  ### File Name Examples - Primary documents: `d123456d10k.htm`, `d789012d8k.htm` - XBRL files: `d123456d10k_htm.xml`, `FilingSummary.xml` - Exhibits: `d123456dexhibit99.htm`, `d123456dex101.htm`  ### File Types The endpoint supports downloading various file types from SEC filings: - HTML documents (.htm, .html) - XBRL files (.xml, .xsd) - Text files (.txt) - PDF files (.pdf) - Other document formats as submitted to SEC  :::tip You can find available filenames for a specific filing using the `/v1/filings` endpoint first :::  :::warning This endpoint streams files directly from the SEC. Large files may take longer to download. :::
    # @param accession_no [String] SEC filing accession number in format: 0000000000-00-000000
    # @param file_name [String] Name of the file to download from the filing
    # @param [Hash] opts the optional parameters
    # @return [nil]
    def v1_download_get(accession_no, file_name, opts = {})
      v1_download_get_with_http_info(accession_no, file_name, opts)
      nil
    end

    # Download file from SEC EDGAR archive
    # Downloads a specific file from the SEC EDGAR archive using the accession number and filename. The file is streamed directly from the SEC servers to the client.  ### Accession Number Format Accession numbers must be in the format: 0000000000-00-000000 (10 digits, dash, 2 digits, dash, 6 digits)  ### File Name Examples - Primary documents: &#x60;d123456d10k.htm&#x60;, &#x60;d789012d8k.htm&#x60; - XBRL files: &#x60;d123456d10k_htm.xml&#x60;, &#x60;FilingSummary.xml&#x60; - Exhibits: &#x60;d123456dexhibit99.htm&#x60;, &#x60;d123456dex101.htm&#x60;  ### File Types The endpoint supports downloading various file types from SEC filings: - HTML documents (.htm, .html) - XBRL files (.xml, .xsd) - Text files (.txt) - PDF files (.pdf) - Other document formats as submitted to SEC  :::tip You can find available filenames for a specific filing using the &#x60;/v1/filings&#x60; endpoint first :::  :::warning This endpoint streams files directly from the SEC. Large files may take longer to download. :::
    # @param accession_no [String] SEC filing accession number in format: 0000000000-00-000000
    # @param file_name [String] Name of the file to download from the filing
    # @param [Hash] opts the optional parameters
    # @return [Array<(nil, Integer, Hash)>] nil, response status code and response headers
    def v1_download_get_with_http_info(accession_no, file_name, opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug 'Calling API: FileDownloadApi.v1_download_get ...'
      end
      # verify the required parameter 'accession_no' is set
      if @api_client.config.client_side_validation && accession_no.nil?
        fail ArgumentError, "Missing the required parameter 'accession_no' when calling FileDownloadApi.v1_download_get"
      end
      pattern = Regexp.new(/^\d{10}-\d{2}-\d{6}$/)
      if @api_client.config.client_side_validation && accession_no !~ pattern
        fail ArgumentError, "invalid value for 'accession_no' when calling FileDownloadApi.v1_download_get, must conform to the pattern #{pattern}."
      end

      # verify the required parameter 'file_name' is set
      if @api_client.config.client_side_validation && file_name.nil?
        fail ArgumentError, "Missing the required parameter 'file_name' when calling FileDownloadApi.v1_download_get"
      end
      # resource path
      local_var_path = '/v1/download'

      # query parameters
      query_params = opts[:query_params] || {}
      query_params[:'accession_no'] = accession_no
      query_params[:'file_name'] = file_name

      # header parameters
      header_params = opts[:header_params] || {}
      # HTTP header 'Accept' (if needed)
      header_params['Accept'] = @api_client.select_header_accept(['application/octet-stream', 'text/html', 'application/xml', 'text/plain', 'application/pdf', '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]

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

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