# coding: utf-8

"""
    The Selling Partner API for Amazon External Fulfillment Return Item Processing

    You can use the Amazon External Fulfillment Return Item Processing API to retrieve, track, and process return items through Amazon's External Fulfillment returns management system.

    The version of the OpenAPI document: 2024-09-11
    Contact: marketplaceapitest@amazon.com
    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 ReturnRetrievalApi(object):
    """NOTE: This class is auto generated by the openapi generator.

    Do not edit the class manually.
    """

    api_models_module = "spapi.models.external_fulfillment_returns_v2024_09_11"

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

    def get_return(self, return_id, **kwargs):  # noqa: E501
        """get_return  # noqa: E501

        Retrieve the return item with the specified ID.  # 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_return(return_id, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str return_id: The ID of the return item you want. (required)
        :return: ModelReturn
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.get_return_with_http_info(return_id, **kwargs)  # noqa: E501
        else:
            (data) = self.get_return_with_http_info(return_id, **kwargs)  # noqa: E501
            return data

    def get_return_with_http_info(self, return_id, **kwargs):  # noqa: E501
        """get_return  # noqa: E501

        Retrieve the return item with the specified ID.  # 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_return_with_http_info(return_id, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str return_id: The ID of the return item you want. (required)
        :return: ModelReturn
                 If the method is called asynchronously,
                 returns the request thread.
        """

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

        collection_formats = {}

        path_params = {}
        if 'return_id' in params:
            path_params['returnId'] = params['return_id']  # noqa: E501

        query_params = []

        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(
            '/externalFulfillment/2024-09-11/returns/{returnId}', 'GET',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='ModelReturn',  # 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 list_returns(self, **kwargs):  # noqa: E501
        """list_returns  # noqa: E501

        Retrieve a list of return items. You can filter results by location, RMA ID, status, or time.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.list_returns(async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str return_location_id: The SmartConnect location ID of the location from which you want to retrieve return items.
        :param str rma_id: The RMA ID of the return items you want to list.
        :param str status: The status of return items you want to list. You can retrieve all new return items with the `CREATED` status.
        :param str reverse_tracking_id: The reverse tracking ID of the return items you want to list.
        :param str created_since: Return items created after the specified date are included in the response. In [ISO 8601](https://developer-docs.amazon.com/sp-api/docs/iso-8601) date-time format.
        :param str created_until: Return items created before the specified date are included in the response. In [ISO 8601](https://developer-docs.amazon.com/sp-api/docs/iso-8601) date-time format.
        :param str last_updated_since: Return items updated after the specified date are included in the response. In [ISO 8601](https://developer-docs.amazon.com/sp-api/docs/iso-8601) date-time format. If you supply this parameter, you must also supply `returnLocationId` and `status`.
        :param str last_updated_until: Return items whose most recent update is before the specified date are included in the response. In [ISO 8601](https://developer-docs.amazon.com/sp-api/docs/iso-8601) date-time format. If you supply this parameter, you must also supply `returnLocationId` and `status`.
        :param str last_updated_after: DEPRECATED. Use the `createdSince` parameter.
        :param str last_updated_before: DEPRECATED. Use the `createdUntil` parameter.
        :param int max_results: The number of return items you want to include in the response.  **Default:** 10  **Maximum:** 100
        :param str next_token: A token that you use to retrieve the next page of results. The response includes `nextToken` when there are multiple pages of results. To get the next page of results, call the operation with this token and include the same arguments as the call that produced the token. To get a complete list, call this operation until `nextToken` is null. Note that this operation can return empty pages.
        :return: ReturnsResponse
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.list_returns_with_http_info(**kwargs)  # noqa: E501
        else:
            (data) = self.list_returns_with_http_info(**kwargs)  # noqa: E501
            return data

    def list_returns_with_http_info(self, **kwargs):  # noqa: E501
        """list_returns  # noqa: E501

        Retrieve a list of return items. You can filter results by location, RMA ID, status, or time.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.list_returns_with_http_info(async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str return_location_id: The SmartConnect location ID of the location from which you want to retrieve return items.
        :param str rma_id: The RMA ID of the return items you want to list.
        :param str status: The status of return items you want to list. You can retrieve all new return items with the `CREATED` status.
        :param str reverse_tracking_id: The reverse tracking ID of the return items you want to list.
        :param str created_since: Return items created after the specified date are included in the response. In [ISO 8601](https://developer-docs.amazon.com/sp-api/docs/iso-8601) date-time format.
        :param str created_until: Return items created before the specified date are included in the response. In [ISO 8601](https://developer-docs.amazon.com/sp-api/docs/iso-8601) date-time format.
        :param str last_updated_since: Return items updated after the specified date are included in the response. In [ISO 8601](https://developer-docs.amazon.com/sp-api/docs/iso-8601) date-time format. If you supply this parameter, you must also supply `returnLocationId` and `status`.
        :param str last_updated_until: Return items whose most recent update is before the specified date are included in the response. In [ISO 8601](https://developer-docs.amazon.com/sp-api/docs/iso-8601) date-time format. If you supply this parameter, you must also supply `returnLocationId` and `status`.
        :param str last_updated_after: DEPRECATED. Use the `createdSince` parameter.
        :param str last_updated_before: DEPRECATED. Use the `createdUntil` parameter.
        :param int max_results: The number of return items you want to include in the response.  **Default:** 10  **Maximum:** 100
        :param str next_token: A token that you use to retrieve the next page of results. The response includes `nextToken` when there are multiple pages of results. To get the next page of results, call the operation with this token and include the same arguments as the call that produced the token. To get a complete list, call this operation until `nextToken` is null. Note that this operation can return empty pages.
        :return: ReturnsResponse
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['return_location_id', 'rma_id', 'status', 'reverse_tracking_id', 'created_since', 'created_until', 'last_updated_since', 'last_updated_until', 'last_updated_after', 'last_updated_before', 'max_results', 'next_token']  # 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 list_returns" % key
                )
            params[key] = val
        del params['kwargs']

        if self.api_client.client_side_validation and ('max_results' in params and params['max_results'] > 100):  # noqa: E501
            raise ValueError("Invalid value for parameter `max_results` when calling `list_returns`, must be a value less than or equal to `100`")  # noqa: E501
        collection_formats = {}

        path_params = {}

        query_params = []
        if 'return_location_id' in params:
            query_params.append(('returnLocationId', params['return_location_id']))  # noqa: E501
        if 'rma_id' in params:
            query_params.append(('rmaId', params['rma_id']))  # noqa: E501
        if 'status' in params:
            query_params.append(('status', params['status']))  # noqa: E501
        if 'reverse_tracking_id' in params:
            query_params.append(('reverseTrackingId', params['reverse_tracking_id']))  # noqa: E501
        if 'created_since' in params:
            query_params.append(('createdSince', params['created_since']))  # noqa: E501
        if 'created_until' in params:
            query_params.append(('createdUntil', params['created_until']))  # noqa: E501
        if 'last_updated_since' in params:
            query_params.append(('lastUpdatedSince', params['last_updated_since']))  # noqa: E501
        if 'last_updated_until' in params:
            query_params.append(('lastUpdatedUntil', params['last_updated_until']))  # noqa: E501
        if 'last_updated_after' in params:
            query_params.append(('lastUpdatedAfter', params['last_updated_after']))  # noqa: E501
        if 'last_updated_before' in params:
            query_params.append(('lastUpdatedBefore', params['last_updated_before']))  # noqa: E501
        if 'max_results' in params:
            query_params.append(('maxResults', params['max_results']))  # noqa: E501
        if 'next_token' in params:
            query_params.append(('nextToken', params['next_token']))  # 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(
            '/externalFulfillment/2024-09-11/returns', 'GET',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='ReturnsResponse',  # 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)
