# coding: utf-8

"""
    CMS Site Search

    Use these endpoints for searching content on your HubSpot hosted CMS website(s).  # noqa: E501

    The version of the OpenAPI document: v3
    Generated by: https://openapi-generator.tech
"""


from __future__ import absolute_import

import re  # noqa: F401

# python 2 and python 3 compatibility library
import six

from hubspot.cms.site_search.api_client import ApiClient
from hubspot.cms.site_search.exceptions import ApiTypeError, ApiValueError  # noqa: F401


class PublicApi(object):
    """NOTE: This class is auto generated by OpenAPI Generator
    Ref: https://openapi-generator.tech

    Do not edit the class manually.
    """

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

    def get_by_id(self, content_id, **kwargs):  # noqa: E501
        """Get indexed properties.  # noqa: E501

        For a given account and document ID (page ID, blog post ID, HubDB row ID, etc.), return all indexed data for that document. This is useful when debugging why a particular document is not returned from a custom search.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True

        >>> thread = api.get_by_id(content_id, async_req=True)
        >>> result = thread.get()

        :param content_id: ID of the target document when searching for indexed properties. (required)
        :type content_id: str
        :param type: The type of document. Can be one of `SITE_PAGE`, `BLOG_POST`, or `KNOWLEDGE_ARTICLE`.
        :type type: str
        :param async_req: Whether to execute the request asynchronously.
        :type async_req: bool, optional
        :param _preload_content: if False, the urllib3.HTTPResponse object will
                                 be returned without reading/decoding response
                                 data. Default is True.
        :type _preload_content: bool, optional
        :param _request_timeout: timeout setting for this request. If one
                                 number provided, it will be total request
                                 timeout. It can also be a pair (tuple) of
                                 (connection, read) timeouts.
        :return: Returns the result object.
                 If the method is called asynchronously,
                 returns the request thread.
        :rtype: IndexedData
        """
        kwargs["_return_http_data_only"] = True
        return self.get_by_id_with_http_info(content_id, **kwargs)  # noqa: E501

    def get_by_id_with_http_info(self, content_id, **kwargs):  # noqa: E501
        """Get indexed properties.  # noqa: E501

        For a given account and document ID (page ID, blog post ID, HubDB row ID, etc.), return all indexed data for that document. This is useful when debugging why a particular document is not returned from a custom search.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True

        >>> thread = api.get_by_id_with_http_info(content_id, async_req=True)
        >>> result = thread.get()

        :param content_id: ID of the target document when searching for indexed properties. (required)
        :type content_id: str
        :param type: The type of document. Can be one of `SITE_PAGE`, `BLOG_POST`, or `KNOWLEDGE_ARTICLE`.
        :type type: str
        :param async_req: Whether to execute the request asynchronously.
        :type async_req: bool, optional
        :param _return_http_data_only: response data without head status code
                                       and headers
        :type _return_http_data_only: bool, optional
        :param _preload_content: if False, the urllib3.HTTPResponse object will
                                 be returned without reading/decoding response
                                 data. Default is True.
        :type _preload_content: bool, optional
        :param _request_timeout: timeout setting for this request. If one
                                 number provided, it will be total request
                                 timeout. It can also be a pair (tuple) of
                                 (connection, read) timeouts.
        :param _request_auth: set to override the auth_settings for an a single
                              request; this effectively ignores the authentication
                              in the spec for a single request.
        :type _request_auth: dict, optional
        :type _content_type: string, optional: force content-type for the request
        :return: Returns the result object.
                 If the method is called asynchronously,
                 returns the request thread.
        :rtype: tuple(IndexedData, status_code(int), headers(HTTPHeaderDict))
        """

        local_var_params = locals()

        all_params = ["content_id", "type"]
        all_params.extend(["async_req", "_return_http_data_only", "_preload_content", "_request_timeout", "_request_auth", "_content_type", "_headers"])

        for key, val in six.iteritems(local_var_params["kwargs"]):
            if key not in all_params:
                raise ApiTypeError("Got an unexpected keyword argument '%s'" " to method get_by_id" % key)
            local_var_params[key] = val
        del local_var_params["kwargs"]
        # verify the required parameter 'content_id' is set
        if self.api_client.client_side_validation and local_var_params.get("content_id") is None:  # noqa: E501
            raise ApiValueError("Missing the required parameter `content_id` when calling `get_by_id`")  # noqa: E501

        if self.api_client.client_side_validation and "content_id" in local_var_params and not re.search(r".*", local_var_params["content_id"]):  # noqa: E501
            raise ApiValueError("Invalid value for parameter `content_id` when calling `get_by_id`, must conform to the pattern `/.*/`")  # noqa: E501
        collection_formats = {}

        path_params = {}
        if "content_id" in local_var_params:
            path_params["contentId"] = local_var_params["content_id"]  # noqa: E501

        query_params = []
        if local_var_params.get("type") is not None:  # noqa: E501
            query_params.append(("type", local_var_params["type"]))  # noqa: E501

        header_params = dict(local_var_params.get("_headers", {}))

        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 = ["oauth2"]  # noqa: E501

        response_types_map = {
            200: "IndexedData",
        }

        return self.api_client.call_api(
            "/cms/v3/site-search/indexed-data/{contentId}",
            "GET",
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_types_map=response_types_map,
            auth_settings=auth_settings,
            async_req=local_var_params.get("async_req"),
            _return_http_data_only=local_var_params.get("_return_http_data_only"),  # noqa: E501
            _preload_content=local_var_params.get("_preload_content", True),
            _request_timeout=local_var_params.get("_request_timeout"),
            collection_formats=collection_formats,
            _request_auth=local_var_params.get("_request_auth"),
        )

    def search(self, **kwargs):  # noqa: E501
        """Search your site.  # noqa: E501

        Returns any website content matching the given search criteria for a given HubSpot account. Searches can be filtered by content type, domain, or URL path.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True

        >>> thread = api.search(async_req=True)
        >>> result = thread.get()

        :param q: The term to search for.
        :type q: str
        :param limit: Specifies the number of results to be returned in a single response. Defaults to `10`. Maximum value is `100`.
        :type limit: int
        :param offset: Used to page through the results. If there are more results than specified by the `limit` parameter, you will need to use the value of offset returned in the previous request to get the next set of results.
        :type offset: int
        :param language: Specifies the language of content to be searched. This value must be a valid [ISO 639-1 language code](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) (e.g. `es` for Spanish)
        :type language: str
        :param match_prefix: Inverts the behavior of the pathPrefix filter when set to `false`. Defaults to `true`.
        :type match_prefix: bool
        :param autocomplete: Specifies whether or not you are showing autocomplete results. Defaults to false.
        :type autocomplete: bool
        :param popularity_boost: Specifies how strongly a result is boosted based on its view count. Defaults to 1.0.
        :type popularity_boost: float
        :param boost_limit: Specifies the maximum amount a result will be boosted based on its view count. Defaults to 5.0. Read more about elasticsearch boosting [here](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-boost.html).
        :type boost_limit: float
        :param boost_recent: Specifies a relative time window where scores of documents published outside this time window decay. This can only be used for blog posts. For example, boostRecent=10d will boost documents published within the last 10 days. Supported timeunits are ms (milliseconds), s (seconds), m (minutes), h (hours), d (days).
        :type boost_recent: str
        :param table_id: Specifies a specific HubDB table to search. Only returns results from the specified table. Can be used in tandem with the `hubdbQuery` parameter to further filter results.
        :type table_id: int
        :param hubdb_query: Specify a HubDB query to further filter the search results.
        :type hubdb_query: str
        :param domain: A domain to match search results for. Multiple domains can be provided with &.
        :type domain: list[str]
        :param type: Specifies the type of content to search. Can be one or more of SITE_PAGE, LANDING_PAGE, BLOG_POST, LISTING_PAGE, and KNOWLEDGE_ARTICLE. Defaults to all content types except LANDING_PAGE and KNOWLEDGE_ARTICLE
        :type type: list[str]
        :param path_prefix: Specifies a path prefix to filter search results. Will only return results with URL paths that start with the specified parameter. Can be used multiple times.
        :type path_prefix: list[str]
        :param _property: Specifies which properties to include in the search. Options include `title`, `description`, and `html`. All properties will be searched by default.
        :type _property: list[str]
        :param length: Specifies the length of the search results. Can be set to `LONG` or `SHORT`. `SHORT` will return the first 128 characters of the content's meta description. `LONG` will build a more detailed content snippet based on the html/content of the page.
        :type length: str
        :param group_id: Specifies which blog(s) to be searched by blog ID. Can be used multiple times to search more than one blog.
        :type group_id: list[int]
        :param async_req: Whether to execute the request asynchronously.
        :type async_req: bool, optional
        :param _preload_content: if False, the urllib3.HTTPResponse object will
                                 be returned without reading/decoding response
                                 data. Default is True.
        :type _preload_content: bool, optional
        :param _request_timeout: timeout setting for this request. If one
                                 number provided, it will be total request
                                 timeout. It can also be a pair (tuple) of
                                 (connection, read) timeouts.
        :return: Returns the result object.
                 If the method is called asynchronously,
                 returns the request thread.
        :rtype: PublicSearchResults
        """
        kwargs["_return_http_data_only"] = True
        return self.search_with_http_info(**kwargs)  # noqa: E501

    def search_with_http_info(self, **kwargs):  # noqa: E501
        """Search your site.  # noqa: E501

        Returns any website content matching the given search criteria for a given HubSpot account. Searches can be filtered by content type, domain, or URL path.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True

        >>> thread = api.search_with_http_info(async_req=True)
        >>> result = thread.get()

        :param q: The term to search for.
        :type q: str
        :param limit: Specifies the number of results to be returned in a single response. Defaults to `10`. Maximum value is `100`.
        :type limit: int
        :param offset: Used to page through the results. If there are more results than specified by the `limit` parameter, you will need to use the value of offset returned in the previous request to get the next set of results.
        :type offset: int
        :param language: Specifies the language of content to be searched. This value must be a valid [ISO 639-1 language code](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) (e.g. `es` for Spanish)
        :type language: str
        :param match_prefix: Inverts the behavior of the pathPrefix filter when set to `false`. Defaults to `true`.
        :type match_prefix: bool
        :param autocomplete: Specifies whether or not you are showing autocomplete results. Defaults to false.
        :type autocomplete: bool
        :param popularity_boost: Specifies how strongly a result is boosted based on its view count. Defaults to 1.0.
        :type popularity_boost: float
        :param boost_limit: Specifies the maximum amount a result will be boosted based on its view count. Defaults to 5.0. Read more about elasticsearch boosting [here](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-boost.html).
        :type boost_limit: float
        :param boost_recent: Specifies a relative time window where scores of documents published outside this time window decay. This can only be used for blog posts. For example, boostRecent=10d will boost documents published within the last 10 days. Supported timeunits are ms (milliseconds), s (seconds), m (minutes), h (hours), d (days).
        :type boost_recent: str
        :param table_id: Specifies a specific HubDB table to search. Only returns results from the specified table. Can be used in tandem with the `hubdbQuery` parameter to further filter results.
        :type table_id: int
        :param hubdb_query: Specify a HubDB query to further filter the search results.
        :type hubdb_query: str
        :param domain: A domain to match search results for. Multiple domains can be provided with &.
        :type domain: list[str]
        :param type: Specifies the type of content to search. Can be one or more of SITE_PAGE, LANDING_PAGE, BLOG_POST, LISTING_PAGE, and KNOWLEDGE_ARTICLE. Defaults to all content types except LANDING_PAGE and KNOWLEDGE_ARTICLE
        :type type: list[str]
        :param path_prefix: Specifies a path prefix to filter search results. Will only return results with URL paths that start with the specified parameter. Can be used multiple times.
        :type path_prefix: list[str]
        :param _property: Specifies which properties to include in the search. Options include `title`, `description`, and `html`. All properties will be searched by default.
        :type _property: list[str]
        :param length: Specifies the length of the search results. Can be set to `LONG` or `SHORT`. `SHORT` will return the first 128 characters of the content's meta description. `LONG` will build a more detailed content snippet based on the html/content of the page.
        :type length: str
        :param group_id: Specifies which blog(s) to be searched by blog ID. Can be used multiple times to search more than one blog.
        :type group_id: list[int]
        :param async_req: Whether to execute the request asynchronously.
        :type async_req: bool, optional
        :param _return_http_data_only: response data without head status code
                                       and headers
        :type _return_http_data_only: bool, optional
        :param _preload_content: if False, the urllib3.HTTPResponse object will
                                 be returned without reading/decoding response
                                 data. Default is True.
        :type _preload_content: bool, optional
        :param _request_timeout: timeout setting for this request. If one
                                 number provided, it will be total request
                                 timeout. It can also be a pair (tuple) of
                                 (connection, read) timeouts.
        :param _request_auth: set to override the auth_settings for an a single
                              request; this effectively ignores the authentication
                              in the spec for a single request.
        :type _request_auth: dict, optional
        :type _content_type: string, optional: force content-type for the request
        :return: Returns the result object.
                 If the method is called asynchronously,
                 returns the request thread.
        :rtype: tuple(PublicSearchResults, status_code(int), headers(HTTPHeaderDict))
        """

        local_var_params = locals()

        all_params = [
            "q",
            "limit",
            "offset",
            "language",
            "match_prefix",
            "autocomplete",
            "popularity_boost",
            "boost_limit",
            "boost_recent",
            "table_id",
            "hubdb_query",
            "domain",
            "type",
            "path_prefix",
            "_property",
            "length",
            "group_id",
        ]
        all_params.extend(["async_req", "_return_http_data_only", "_preload_content", "_request_timeout", "_request_auth", "_content_type", "_headers"])

        for key, val in six.iteritems(local_var_params["kwargs"]):
            if key not in all_params:
                raise ApiTypeError("Got an unexpected keyword argument '%s'" " to method search" % key)
            local_var_params[key] = val
        del local_var_params["kwargs"]

        collection_formats = {}

        path_params = {}

        query_params = []
        if local_var_params.get("q") is not None:  # noqa: E501
            query_params.append(("q", local_var_params["q"]))  # noqa: E501
        if local_var_params.get("limit") is not None:  # noqa: E501
            query_params.append(("limit", local_var_params["limit"]))  # noqa: E501
        if local_var_params.get("offset") is not None:  # noqa: E501
            query_params.append(("offset", local_var_params["offset"]))  # noqa: E501
        if local_var_params.get("language") is not None:  # noqa: E501
            query_params.append(("language", local_var_params["language"]))  # noqa: E501
        if local_var_params.get("match_prefix") is not None:  # noqa: E501
            query_params.append(("matchPrefix", local_var_params["match_prefix"]))  # noqa: E501
        if local_var_params.get("autocomplete") is not None:  # noqa: E501
            query_params.append(("autocomplete", local_var_params["autocomplete"]))  # noqa: E501
        if local_var_params.get("popularity_boost") is not None:  # noqa: E501
            query_params.append(("popularityBoost", local_var_params["popularity_boost"]))  # noqa: E501
        if local_var_params.get("boost_limit") is not None:  # noqa: E501
            query_params.append(("boostLimit", local_var_params["boost_limit"]))  # noqa: E501
        if local_var_params.get("boost_recent") is not None:  # noqa: E501
            query_params.append(("boostRecent", local_var_params["boost_recent"]))  # noqa: E501
        if local_var_params.get("table_id") is not None:  # noqa: E501
            query_params.append(("tableId", local_var_params["table_id"]))  # noqa: E501
        if local_var_params.get("hubdb_query") is not None:  # noqa: E501
            query_params.append(("hubdbQuery", local_var_params["hubdb_query"]))  # noqa: E501
        if local_var_params.get("domain") is not None:  # noqa: E501
            query_params.append(("domain", local_var_params["domain"]))  # noqa: E501
            collection_formats["domain"] = "multi"  # noqa: E501
        if local_var_params.get("type") is not None:  # noqa: E501
            query_params.append(("type", local_var_params["type"]))  # noqa: E501
            collection_formats["type"] = "multi"  # noqa: E501
        if local_var_params.get("path_prefix") is not None:  # noqa: E501
            query_params.append(("pathPrefix", local_var_params["path_prefix"]))  # noqa: E501
            collection_formats["pathPrefix"] = "multi"  # noqa: E501
        if local_var_params.get("_property") is not None:  # noqa: E501
            query_params.append(("property", local_var_params["_property"]))  # noqa: E501
            collection_formats["property"] = "multi"  # noqa: E501
        if local_var_params.get("length") is not None:  # noqa: E501
            query_params.append(("length", local_var_params["length"]))  # noqa: E501
        if local_var_params.get("group_id") is not None:  # noqa: E501
            query_params.append(("groupId", local_var_params["group_id"]))  # noqa: E501
            collection_formats["groupId"] = "multi"  # noqa: E501

        header_params = dict(local_var_params.get("_headers", {}))

        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 = ["oauth2"]  # noqa: E501

        response_types_map = {
            200: "PublicSearchResults",
        }

        return self.api_client.call_api(
            "/cms/v3/site-search/search",
            "GET",
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_types_map=response_types_map,
            auth_settings=auth_settings,
            async_req=local_var_params.get("async_req"),
            _return_http_data_only=local_var_params.get("_return_http_data_only"),  # noqa: E501
            _preload_content=local_var_params.get("_preload_content", True),
            _request_timeout=local_var_params.get("_request_timeout"),
            collection_formats=collection_formats,
            _request_auth=local_var_params.get("_request_auth"),
        )
