# coding: utf-8

"""
    Selling Partner API for Product Type Definitions

    The Selling Partner API for Product Type Definitions provides programmatic access to attribute and data requirements for product types in the Amazon catalog. Use this API to return the JSON Schema for a product type that you can then use with other Selling Partner APIs, such as the Selling Partner API for Listings Items, the Selling Partner API for Catalog Items, and the Selling Partner API for Feeds (for JSON-based listing feeds).  For more information, see the [Product Type Definitions API Use Case Guide](doc:product-type-api-use-case-guide).

    The version of the OpenAPI document: 2020-09-01
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501


from __future__ import absolute_import

import re  # noqa: F401

# python 2 and python 3 compatibility library
import six

from spapi.api_client import ApiClient


class DefinitionsApi(object):
    """NOTE: This class is auto generated by the openapi generator.

    Do not edit the class manually.
    """

    api_models_module = "spapi.models.product_type_definitions_v2020_09_01"

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

    def get_definitions_product_type(self, product_type, marketplace_ids, **kwargs):  # noqa: E501
        """get_definitions_product_type  # noqa: E501

        Retrieve an Amazon product type definition.  **Usage Plans:**  | Plan type | Rate (requests per second) | Burst | | ---- | ---- | ---- | |Default| 5 | 10 | |Selling partner specific| Variable | Variable |  The x-amzn-RateLimit-Limit response header returns the usage plan rate limits that were applied to the requested operation. Rate limits for some selling partners will vary from the default rate and burst shown in the table above. For more information, see [Usage Plans and Rate Limits in the Selling Partner API](doc:usage-plans-and-rate-limits-in-the-sp-api).  # 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_definitions_product_type(product_type, marketplace_ids, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str product_type: The Amazon product type name. (required)
        :param List[str] marketplace_ids: A comma-delimited list of Amazon marketplace identifiers for the request. Note: This parameter is limited to one marketplaceId at this time. (required)
        :param str seller_id: A selling partner identifier. When provided, seller-specific requirements and values are populated within the product type definition schema, such as brand names associated with the selling partner.
        :param str product_type_version: The version of the Amazon product type to retrieve. Defaults to \"LATEST\",. Prerelease versions of product type definitions may be retrieved with \"RELEASE_CANDIDATE\". If no prerelease version is currently available, the \"LATEST\" live version will be provided.
        :param str requirements: The name of the requirements set to retrieve requirements for.
        :param str requirements_enforced: Identifies if the required attributes for a requirements set are enforced by the product type definition schema. Non-enforced requirements enable structural validation of individual attributes without all the required attributes being present (such as for partial updates).
        :param str locale: Locale for retrieving display labels and other presentation details. Defaults to the default language of the first marketplace in the request.
        :return: ProductTypeDefinition
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.get_definitions_product_type_with_http_info(product_type, marketplace_ids, **kwargs)  # noqa: E501
        else:
            (data) = self.get_definitions_product_type_with_http_info(product_type, marketplace_ids, **kwargs)  # noqa: E501
            return data

    def get_definitions_product_type_with_http_info(self, product_type, marketplace_ids, **kwargs):  # noqa: E501
        """get_definitions_product_type  # noqa: E501

        Retrieve an Amazon product type definition.  **Usage Plans:**  | Plan type | Rate (requests per second) | Burst | | ---- | ---- | ---- | |Default| 5 | 10 | |Selling partner specific| Variable | Variable |  The x-amzn-RateLimit-Limit response header returns the usage plan rate limits that were applied to the requested operation. Rate limits for some selling partners will vary from the default rate and burst shown in the table above. For more information, see [Usage Plans and Rate Limits in the Selling Partner API](doc:usage-plans-and-rate-limits-in-the-sp-api).  # 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_definitions_product_type_with_http_info(product_type, marketplace_ids, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str product_type: The Amazon product type name. (required)
        :param List[str] marketplace_ids: A comma-delimited list of Amazon marketplace identifiers for the request. Note: This parameter is limited to one marketplaceId at this time. (required)
        :param str seller_id: A selling partner identifier. When provided, seller-specific requirements and values are populated within the product type definition schema, such as brand names associated with the selling partner.
        :param str product_type_version: The version of the Amazon product type to retrieve. Defaults to \"LATEST\",. Prerelease versions of product type definitions may be retrieved with \"RELEASE_CANDIDATE\". If no prerelease version is currently available, the \"LATEST\" live version will be provided.
        :param str requirements: The name of the requirements set to retrieve requirements for.
        :param str requirements_enforced: Identifies if the required attributes for a requirements set are enforced by the product type definition schema. Non-enforced requirements enable structural validation of individual attributes without all the required attributes being present (such as for partial updates).
        :param str locale: Locale for retrieving display labels and other presentation details. Defaults to the default language of the first marketplace in the request.
        :return: ProductTypeDefinition
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['product_type', 'marketplace_ids', 'seller_id', 'product_type_version', 'requirements', 'requirements_enforced', 'locale']  # 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_definitions_product_type" % key
                )
            params[key] = val
        del params['kwargs']
        # verify the required parameter 'product_type' is set
        if self.api_client.client_side_validation and ('product_type' not in params or
                                                       params['product_type'] is None):  # noqa: E501
            raise ValueError("Missing the required parameter `product_type` when calling `get_definitions_product_type`")  # noqa: E501
        # verify the required parameter 'marketplace_ids' is set
        if self.api_client.client_side_validation and ('marketplace_ids' not in params or
                                                       params['marketplace_ids'] is None):  # noqa: E501
            raise ValueError("Missing the required parameter `marketplace_ids` when calling `get_definitions_product_type`")  # noqa: E501

        collection_formats = {}

        path_params = {}
        if 'product_type' in params:
            path_params['productType'] = params['product_type']  # noqa: E501

        query_params = []
        if 'seller_id' in params:
            query_params.append(('sellerId', params['seller_id']))  # noqa: E501
        if 'marketplace_ids' in params:
            query_params.append(('marketplaceIds', params['marketplace_ids']))  # noqa: E501
            collection_formats['marketplaceIds'] = 'csv'  # noqa: E501
        if 'product_type_version' in params:
            query_params.append(('productTypeVersion', params['product_type_version']))  # noqa: E501
        if 'requirements' in params:
            query_params.append(('requirements', params['requirements']))  # noqa: E501
        if 'requirements_enforced' in params:
            query_params.append(('requirementsEnforced', params['requirements_enforced']))  # noqa: E501
        if 'locale' in params:
            query_params.append(('locale', params['locale']))  # 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 = []  # noqa: E501

        return self.api_client.call_api(
            '/definitions/2020-09-01/productTypes/{productType}', 'GET',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='ProductTypeDefinition',  # 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, api_models_module=self.api_models_module)

    def search_definitions_product_types(self, marketplace_ids, **kwargs):  # noqa: E501
        """search_definitions_product_types  # noqa: E501

        Search for and return a list of Amazon product types that have definitions available.  **Usage Plans:**  | Plan type | Rate (requests per second) | Burst | | ---- | ---- | ---- | |Default| 5 | 10 | |Selling partner specific| Variable | Variable |  The x-amzn-RateLimit-Limit response header returns the usage plan rate limits that were applied to the requested operation. Rate limits for some selling partners will vary from the default rate and burst shown in the table above. For more information, see [Usage Plans and Rate Limits in the Selling Partner API](doc:usage-plans-and-rate-limits-in-the-sp-api).  # 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_definitions_product_types(marketplace_ids, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param List[str] marketplace_ids: A comma-delimited list of Amazon marketplace identifiers for the request. (required)
        :param List[str] keywords: A comma-delimited list of keywords to search product types. **Note:** Cannot be used with `itemName`.
        :param str item_name: The title of the ASIN to get the product type recommendation. **Note:** Cannot be used with `keywords`.
        :param str locale: The locale for the display names in the response. Defaults to the primary locale of the marketplace.
        :param str search_locale: The locale used for the `keywords` and `itemName` parameters. Defaults to the primary locale of the marketplace.
        :return: ProductTypeList
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.search_definitions_product_types_with_http_info(marketplace_ids, **kwargs)  # noqa: E501
        else:
            (data) = self.search_definitions_product_types_with_http_info(marketplace_ids, **kwargs)  # noqa: E501
            return data

    def search_definitions_product_types_with_http_info(self, marketplace_ids, **kwargs):  # noqa: E501
        """search_definitions_product_types  # noqa: E501

        Search for and return a list of Amazon product types that have definitions available.  **Usage Plans:**  | Plan type | Rate (requests per second) | Burst | | ---- | ---- | ---- | |Default| 5 | 10 | |Selling partner specific| Variable | Variable |  The x-amzn-RateLimit-Limit response header returns the usage plan rate limits that were applied to the requested operation. Rate limits for some selling partners will vary from the default rate and burst shown in the table above. For more information, see [Usage Plans and Rate Limits in the Selling Partner API](doc:usage-plans-and-rate-limits-in-the-sp-api).  # 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_definitions_product_types_with_http_info(marketplace_ids, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param List[str] marketplace_ids: A comma-delimited list of Amazon marketplace identifiers for the request. (required)
        :param List[str] keywords: A comma-delimited list of keywords to search product types. **Note:** Cannot be used with `itemName`.
        :param str item_name: The title of the ASIN to get the product type recommendation. **Note:** Cannot be used with `keywords`.
        :param str locale: The locale for the display names in the response. Defaults to the primary locale of the marketplace.
        :param str search_locale: The locale used for the `keywords` and `itemName` parameters. Defaults to the primary locale of the marketplace.
        :return: ProductTypeList
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['marketplace_ids', 'keywords', 'item_name', 'locale', 'search_locale']  # 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 search_definitions_product_types" % key
                )
            params[key] = val
        del params['kwargs']
        # verify the required parameter 'marketplace_ids' is set
        if self.api_client.client_side_validation and ('marketplace_ids' not in params or
                                                       params['marketplace_ids'] is None):  # noqa: E501
            raise ValueError("Missing the required parameter `marketplace_ids` when calling `search_definitions_product_types`")  # noqa: E501

        collection_formats = {}

        path_params = {}

        query_params = []
        if 'keywords' in params:
            query_params.append(('keywords', params['keywords']))  # noqa: E501
            collection_formats['keywords'] = 'csv'  # noqa: E501
        if 'marketplace_ids' in params:
            query_params.append(('marketplaceIds', params['marketplace_ids']))  # noqa: E501
            collection_formats['marketplaceIds'] = 'csv'  # noqa: E501
        if 'item_name' in params:
            query_params.append(('itemName', params['item_name']))  # noqa: E501
        if 'locale' in params:
            query_params.append(('locale', params['locale']))  # noqa: E501
        if 'search_locale' in params:
            query_params.append(('searchLocale', params['search_locale']))  # 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 = []  # noqa: E501

        return self.api_client.call_api(
            '/definitions/2020-09-01/productTypes', 'GET',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='ProductTypeList',  # 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, api_models_module=self.api_models_module)
