# coding: utf-8

"""
    Brave Web Search API

    The Brave Web Search API allows developers to integrate web search capabilities from the Brave Search engine into their applications.  It supports querying Brave's index with advanced options for filtering, pagination, and customizing the search results format.  Designed for developers building tools like search engines, content discovery platforms, or analytics applications.   # noqa: E501

    OpenAPI spec version: 1.0.0
    
    Generated by: https://github.com/swagger-api/swagger-codegen.git
"""

from __future__ import absolute_import

import re  # noqa: F401

# python 2 and python 3 compatibility library
import six

from ..api_client import ApiClient


class DefaultApi(object):
    """NOTE: This class is auto generated by the swagger code generator program.

    Do not edit the class manually.
    Ref: https://github.com/swagger-api/swagger-codegen
    """

    def __init__(self, api_client=None):
        if api_client is None:
            api_client = ApiClient()
        self.api_client = api_client

    def brave_search_get_web_search_results(self, q, **kwargs):  # noqa: E501
        """Get detailed web search results  # noqa: E501

        This endpoint allows you to perform a web search using Brave's search engine. It provides detailed search results based on the query term you specify, along with optional filters to refine your search. You can apply safe search settings, filter results by their freshness, and customize how the results are formatted. The output includes a list of search results with titles, descriptions, URLs, and additional metadata, making it suitable for deep integration into applications that require web search functionality.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.brave_search_get_web_search_results(q, async_req=True)
        >>> result = thread.get()

        :param async_req bool:
        :param str q: The search query term. Use this parameter to specify the topic, keywords, or phrases to search for in Brave's web index. Example: 'climate change impacts'.  (required)
        :param int count: Specifies the number of search results to return per request, with a maximum value of 20.  Useful for controlling the number of items displayed in paginated lists. Example: 10. 
        :param int offset: The zero-based offset for paginating search results. Use this parameter to skip a number of results. For example, setting `offset=10` skips the first 10 results and retrieves the next set. 
        :param str safesearch: A filter to control the inclusion of adult or explicit content in the search results. Options: - `off`: No filtering (all content types included). - `moderate`: Filters explicit images and videos (default). - `strict`: Strict filtering of adult content. 
        :param str freshness: Restricts search results based on when the content was indexed by Brave Search.  Options: - `pd`: Results from the past day. - `pw`: Results from the past week. - `pm`: Results from the past month. - `py`: Results from the past year. 
        :param bool text_decorations: Indicates whether to include highlighting or decoration markers (e.g., bolding keywords) in display strings for search results. Example: true (default). 
        :param bool spellcheck: Enables or disables spellchecking for the query. When enabled, the API corrects misspelled words in the query to improve result relevance. Example: true (default). 
        :param str result_filter: A comma-separated list of specific result types to include in the response. Examples: - `news,images` (to include only news articles and images). 
        :param str goggles_id: Applies custom re-ranking logic on top of the Brave Search index.  Use this parameter with a valid `goggles_id` value for personalized results. 
        :param str units: The preferred system of measurement for displaying unit-based content in search results. Options: - `metric`: Metric units (kilometers, kilograms, etc.). - `imperial`: Imperial units (miles, pounds, etc.). 
        :param bool extra_snippets: Allows the API to return up to 5 alternative excerpts for each result.  Useful for presenting users with multiple contexts or descriptions for a single item. 
        :param bool summary: Enables the generation of summary keys for web search results, providing concise overviews of the content. 
        :return: InlineResponse200
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.brave_search_get_web_search_results_with_http_info(q, **kwargs)  # noqa: E501
        else:
            (data) = self.brave_search_get_web_search_results_with_http_info(q, **kwargs)  # noqa: E501
            return data

    def brave_search_get_web_search_results_with_http_info(self, q, **kwargs):  # noqa: E501
        """Get detailed web search results  # noqa: E501

        This endpoint allows you to perform a web search using Brave's search engine. It provides detailed search results based on the query term you specify, along with optional filters to refine your search. You can apply safe search settings, filter results by their freshness, and customize how the results are formatted. The output includes a list of search results with titles, descriptions, URLs, and additional metadata, making it suitable for deep integration into applications that require web search functionality.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.brave_search_get_web_search_results_with_http_info(q, async_req=True)
        >>> result = thread.get()

        :param async_req bool:
        :param str q: The search query term. Use this parameter to specify the topic, keywords, or phrases to search for in Brave's web index. Example: 'climate change impacts'.  (required)
        :param int count: Specifies the number of search results to return per request, with a maximum value of 20.  Useful for controlling the number of items displayed in paginated lists. Example: 10. 
        :param int offset: The zero-based offset for paginating search results. Use this parameter to skip a number of results. For example, setting `offset=10` skips the first 10 results and retrieves the next set. 
        :param str safesearch: A filter to control the inclusion of adult or explicit content in the search results. Options: - `off`: No filtering (all content types included). - `moderate`: Filters explicit images and videos (default). - `strict`: Strict filtering of adult content. 
        :param str freshness: Restricts search results based on when the content was indexed by Brave Search.  Options: - `pd`: Results from the past day. - `pw`: Results from the past week. - `pm`: Results from the past month. - `py`: Results from the past year. 
        :param bool text_decorations: Indicates whether to include highlighting or decoration markers (e.g., bolding keywords) in display strings for search results. Example: true (default). 
        :param bool spellcheck: Enables or disables spellchecking for the query. When enabled, the API corrects misspelled words in the query to improve result relevance. Example: true (default). 
        :param str result_filter: A comma-separated list of specific result types to include in the response. Examples: - `news,images` (to include only news articles and images). 
        :param str goggles_id: Applies custom re-ranking logic on top of the Brave Search index.  Use this parameter with a valid `goggles_id` value for personalized results. 
        :param str units: The preferred system of measurement for displaying unit-based content in search results. Options: - `metric`: Metric units (kilometers, kilograms, etc.). - `imperial`: Imperial units (miles, pounds, etc.). 
        :param bool extra_snippets: Allows the API to return up to 5 alternative excerpts for each result.  Useful for presenting users with multiple contexts or descriptions for a single item. 
        :param bool summary: Enables the generation of summary keys for web search results, providing concise overviews of the content. 
        :return: InlineResponse200
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['q', 'count', 'offset', 'safesearch', 'freshness', 'text_decorations', 'spellcheck', 'result_filter', 'goggles_id', 'units', 'extra_snippets', 'summary']  # noqa: E501
        all_params.append('async_req')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        params = locals()
        for key, val in six.iteritems(params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method brave_search_get_web_search_results" % key
                )
            params[key] = val
        del params['kwargs']
        # verify the required parameter 'q' is set
        if ('q' not in params or
                params['q'] is None):
            raise ValueError("Missing the required parameter `q` when calling `brave_search_get_web_search_results`")  # noqa: E501

        collection_formats = {}

        path_params = {}

        query_params = []
        if 'q' in params:
            query_params.append(('q', params['q']))  # noqa: E501
        if 'count' in params:
            query_params.append(('count', params['count']))  # noqa: E501
        if 'offset' in params:
            query_params.append(('offset', params['offset']))  # noqa: E501
        if 'safesearch' in params:
            query_params.append(('safesearch', params['safesearch']))  # noqa: E501
        if 'freshness' in params:
            query_params.append(('freshness', params['freshness']))  # noqa: E501
        if 'text_decorations' in params:
            query_params.append(('text_decorations', params['text_decorations']))  # noqa: E501
        if 'spellcheck' in params:
            query_params.append(('spellcheck', params['spellcheck']))  # noqa: E501
        if 'result_filter' in params:
            query_params.append(('result_filter', params['result_filter']))  # noqa: E501
        if 'goggles_id' in params:
            query_params.append(('goggles_id', params['goggles_id']))  # noqa: E501
        if 'units' in params:
            query_params.append(('units', params['units']))  # noqa: E501
        if 'extra_snippets' in params:
            query_params.append(('extra_snippets', params['extra_snippets']))  # noqa: E501
        if 'summary' in params:
            query_params.append(('summary', params['summary']))  # noqa: E501

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.select_header_accept(
            ['application/json'])  # noqa: E501

        # Authentication setting
        auth_settings = ['apiKey']  # noqa: E501

        return self.api_client.call_api(
            '/res/v1/web/search', 'GET',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='InlineResponse200',  # noqa: E501
            auth_settings=auth_settings,
            async_req=params.get('async_req'),
            _return_http_data_only=params.get('_return_http_data_only'),
            _preload_content=params.get('_preload_content', True),
            _request_timeout=params.get('_request_timeout'),
            collection_formats=collection_formats)
