# coding: utf-8

"""
    Buy Marketing Api

    The Marketing API retrieves eBay products based on a metric, such as Best Selling, as well as products that were also bought and also viewed.  # noqa: E501

    OpenAPI spec version: 1.1.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 ...buy_marketing.api_client import ApiClient


class SimilarItemsApi(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 get_similar_items(self, item_id, **kwargs):  # noqa: E501
        """get_similar_items  # noqa: E501

        This method retrieves items that are similar to the specified item.<br><br>Items are considered <i>similar</i> if they can serve as a replacement or alternative for the specified item. Similar items from a catalog are associated with the same product. For items not associated with a product, similarity is determined by keywords in the title and attribute value matches.<br><br>The item for which to retrieve similar items is specified by its <b>item_id</b> value, input as a required query parameter. A successful call returns a list of items similar to the specified item, as well as details about each item. This includes the current price and shipping costs are returned for each item, as well as basic information about the listing, such as its item ID, price, shipping cost, and time left on the listing.  # 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_similar_items(item_id, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str item_id: This query parameter specifies the unique RESTful identifier of the item for which to retrieve similar items. <br><br><b>RESTful Item ID Format: </b><code>v1</code>|<code><i>#</i></code>|<code><i>#</i></code><br><br>For a single SKU listing, pass in the item ID: <pre>v1|2**********2|0</pre>For a multi-SKU listing, pass in the identifier of the variation:<pre>v1|1**********2|4**********2</pre><br>For more information about item IDs for RESTful APIs, refer to <a href=\"/api-docs/buy/static/api-browse.html#Legacy\" target=\"_blank\">Item ID legacy API compatibility overview</a> in the <a href=\"/api-docs/buy/static/buying-ig-landing.html\" target=\"_blank\">Buying Integration Guide</a>. (required)
        :param str accept_language: This header is used to indicate the natural language and locale preferred by the user for the response.<br><br>This header is required when targeting a specific locale of a marketplace that supports multiple locales. For example:<ul><li>When targeting the French locale of the Belgium marketplace, it is required to pass in <code>fr-BE</code> to specify this. If this locale is not specified, the language will default to Dutch.</li><li>When targeting the French locale of the Canadian marketplace, it is required to pass in <code>fr-CA</code> to specify this. If this locale is not specified, the language will default to English.</li></ul>
        :param str buying_option: This query parameter can be used to filter the result set based on the item's buying option type.<br><br><b>Valid Values:</b><ul><li><code>FIXED_PRICE</code></li><li><code>AUCTION</code></li><li><code>BEST_OFFER</code></li><li><code>CLASSIFIED_AD</code></li></ul>
        :param str excluded_category_ids: This query parameter can be used to specify categories to exclude from the result set.<br><br>Because the list of eBay category IDs is not published and category IDs are not the same across all eBay marketplaces, category IDs may be determined by:<ul><li>Visiting the <a href=\"https://pages.ebay.com/sellerinformation/news/categorychanges.html \" target=\"_blank\">Category Changes page</a></li><li>Using the <b>Taxonomy API</b>. Refer to <a href=\"/api-docs/buy/buy-categories.html\" target=\"_blank\">Get Categories for Buy APIs</a> for complete information.</li><li>Issuing the following call to retrieve the <code>dominantCategoryId</code> for an item:<pre>/buy/browse/v1/item_summary/search?q=<i> keyword</i>&fieldgroups=ASPECT_REFINEMENTS</pre></li></ul><br>Up to three categories to be excluded can be specified through this parameter.
        :param str filter: An array of field filters that can be used to limit/customize the result set.<br><br>Currently, only <code>itemEndDate</code> is supported. This filter limits the result set to include only items scheduled to end before the specified date and time. For example, <pre>filter=itemEndDate:[..2025-12-14T07:47:48Z]</pre> For implementation help, refer to eBay API documentation at https://developer.ebay.com/api-docs/buy/marketing/types/api:FilterField
        :param str max_results: This query parameter can be used to specify the max number of items to display from the result set.<br><br><b>Default:</b> 20<br><br><b>Max value:</b> 50
        :param str x_ebay_c_enduserctx: This header can be used to pass in affiliate credentials to return item affiliate information. For more information, see <a href=\"/api-docs/buy/static/api-browse.html#affiliate-header\" target=\"_blank \">Header for affiliate information.</a>
        :param str x_ebay_c_marketplace_id: This header identifies the seller's eBay marketplace. It is required for all marketplaces outside of the US.<br><br><span class=\"tablenote\"><b>Note:</b> If the marketplace ID value is invalid or missing, the default value of <code>EBAY_US</code> is used.</span><br>See <a href=\"/api-docs/buy/browse/types/ba:MarketplaceIdEnum\" target=\"_blank\">MarketplaceIdEnum</a> for a list of supported marketplaces.<br><br><b>Default:</b> <code>EBAY_US</code>
        :return: SimilarItemsResponse
                 If the method is called asynchronously,
                 returns the request thread.
        """
        if '_return_http_data_only' not in kwargs:  # ebay_rest patch
            kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.get_similar_items_with_http_info(item_id, **kwargs)  # noqa: E501
        else:
            (data) = self.get_similar_items_with_http_info(item_id, **kwargs)  # noqa: E501
            return data

    def get_similar_items_with_http_info(self, item_id, **kwargs):  # noqa: E501
        """get_similar_items  # noqa: E501

        This method retrieves items that are similar to the specified item.<br><br>Items are considered <i>similar</i> if they can serve as a replacement or alternative for the specified item. Similar items from a catalog are associated with the same product. For items not associated with a product, similarity is determined by keywords in the title and attribute value matches.<br><br>The item for which to retrieve similar items is specified by its <b>item_id</b> value, input as a required query parameter. A successful call returns a list of items similar to the specified item, as well as details about each item. This includes the current price and shipping costs are returned for each item, as well as basic information about the listing, such as its item ID, price, shipping cost, and time left on the listing.  # 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_similar_items_with_http_info(item_id, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str item_id: This query parameter specifies the unique RESTful identifier of the item for which to retrieve similar items. <br><br><b>RESTful Item ID Format: </b><code>v1</code>|<code><i>#</i></code>|<code><i>#</i></code><br><br>For a single SKU listing, pass in the item ID: <pre>v1|2**********2|0</pre>For a multi-SKU listing, pass in the identifier of the variation:<pre>v1|1**********2|4**********2</pre><br>For more information about item IDs for RESTful APIs, refer to <a href=\"/api-docs/buy/static/api-browse.html#Legacy\" target=\"_blank\">Item ID legacy API compatibility overview</a> in the <a href=\"/api-docs/buy/static/buying-ig-landing.html\" target=\"_blank\">Buying Integration Guide</a>. (required)
        :param str accept_language: This header is used to indicate the natural language and locale preferred by the user for the response.<br><br>This header is required when targeting a specific locale of a marketplace that supports multiple locales. For example:<ul><li>When targeting the French locale of the Belgium marketplace, it is required to pass in <code>fr-BE</code> to specify this. If this locale is not specified, the language will default to Dutch.</li><li>When targeting the French locale of the Canadian marketplace, it is required to pass in <code>fr-CA</code> to specify this. If this locale is not specified, the language will default to English.</li></ul>
        :param str buying_option: This query parameter can be used to filter the result set based on the item's buying option type.<br><br><b>Valid Values:</b><ul><li><code>FIXED_PRICE</code></li><li><code>AUCTION</code></li><li><code>BEST_OFFER</code></li><li><code>CLASSIFIED_AD</code></li></ul>
        :param str excluded_category_ids: This query parameter can be used to specify categories to exclude from the result set.<br><br>Because the list of eBay category IDs is not published and category IDs are not the same across all eBay marketplaces, category IDs may be determined by:<ul><li>Visiting the <a href=\"https://pages.ebay.com/sellerinformation/news/categorychanges.html \" target=\"_blank\">Category Changes page</a></li><li>Using the <b>Taxonomy API</b>. Refer to <a href=\"/api-docs/buy/buy-categories.html\" target=\"_blank\">Get Categories for Buy APIs</a> for complete information.</li><li>Issuing the following call to retrieve the <code>dominantCategoryId</code> for an item:<pre>/buy/browse/v1/item_summary/search?q=<i> keyword</i>&fieldgroups=ASPECT_REFINEMENTS</pre></li></ul><br>Up to three categories to be excluded can be specified through this parameter.
        :param str filter: An array of field filters that can be used to limit/customize the result set.<br><br>Currently, only <code>itemEndDate</code> is supported. This filter limits the result set to include only items scheduled to end before the specified date and time. For example, <pre>filter=itemEndDate:[..2025-12-14T07:47:48Z]</pre> For implementation help, refer to eBay API documentation at https://developer.ebay.com/api-docs/buy/marketing/types/api:FilterField
        :param str max_results: This query parameter can be used to specify the max number of items to display from the result set.<br><br><b>Default:</b> 20<br><br><b>Max value:</b> 50
        :param str x_ebay_c_enduserctx: This header can be used to pass in affiliate credentials to return item affiliate information. For more information, see <a href=\"/api-docs/buy/static/api-browse.html#affiliate-header\" target=\"_blank \">Header for affiliate information.</a>
        :param str x_ebay_c_marketplace_id: This header identifies the seller's eBay marketplace. It is required for all marketplaces outside of the US.<br><br><span class=\"tablenote\"><b>Note:</b> If the marketplace ID value is invalid or missing, the default value of <code>EBAY_US</code> is used.</span><br>See <a href=\"/api-docs/buy/browse/types/ba:MarketplaceIdEnum\" target=\"_blank\">MarketplaceIdEnum</a> for a list of supported marketplaces.<br><br><b>Default:</b> <code>EBAY_US</code>
        :return: SimilarItemsResponse
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['item_id', 'accept_language', 'buying_option', 'excluded_category_ids', 'filter', 'max_results', 'x_ebay_c_enduserctx', 'x_ebay_c_marketplace_id']  # 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 get_similar_items" % key
                )
            params[key] = val
        del params['kwargs']
        # verify the required parameter 'item_id' is set
        if ('item_id' not in params or
                params['item_id'] is None):
            raise ValueError("Missing the required parameter `item_id` when calling `get_similar_items`")  # noqa: E501

        collection_formats = {}

        path_params = {}

        query_params = []
        if 'buying_option' in params:
            query_params.append(('buying_option', params['buying_option']))  # noqa: E501
        if 'excluded_category_ids' in params:
            query_params.append(('excluded_category_ids', params['excluded_category_ids']))  # noqa: E501
        if 'filter' in params:
            query_params.append(('filter', params['filter']))  # noqa: E501
        if 'item_id' in params:
            query_params.append(('item_id', params['item_id']))  # noqa: E501
        if 'max_results' in params:
            query_params.append(('max_results', params['max_results']))  # noqa: E501

        header_params = {}
        if 'accept_language' in params:
            header_params['Accept-Language'] = params['accept_language']  # noqa: E501
        if 'x_ebay_c_enduserctx' in params:
            header_params['X-EBAY-C-ENDUSERCTX'] = params['x_ebay_c_enduserctx']  # noqa: E501
        if 'x_ebay_c_marketplace_id' in params:
            header_params['X-EBAY-C-MARKETPLACE-ID'] = params['x_ebay_c_marketplace_id']  # noqa: E501

        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 = ['api_auth']  # noqa: E501

        return self.api_client.call_api(
            '/similar_items', 'GET',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='SimilarItemsResponse',  # 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)
