# coding: utf-8

"""
    The Selling Partner API for Amazon External Fulfillment Shipments Processing

    You can use the External Fulfillment Shipments API to retrieve, manage, and track shipments processed through Amazon's external fulfillment network. Use this API to get shipment details, monitor status changes, and access fulfillment requirements.

    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 ShipmentRetrievalApi(object):
    """NOTE: This class is auto generated by the openapi generator.

    Do not edit the class manually.
    """

    api_models_module = "spapi.models.external_fulfillment_shipments_v2024_09_11"

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

    def get_shipment(self, shipment_id, **kwargs):  # noqa: E501
        """get_shipment  # noqa: E501

        Get a single shipment with the ID you specify.  # 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_shipment(shipment_id, async_req=True)
        >>> result = thread.get()

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

    def get_shipment_with_http_info(self, shipment_id, **kwargs):  # noqa: E501
        """get_shipment  # noqa: E501

        Get a single shipment with the ID you specify.  # 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_shipment_with_http_info(shipment_id, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str shipment_id: The ID of the shipment you want to retrieve. (required)
        :return: Shipment
                 If the method is called asynchronously,
                 returns the request thread.
        """

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

        collection_formats = {}

        path_params = {}
        if 'shipment_id' in params:
            path_params['shipmentId'] = params['shipment_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/shipments/{shipmentId}', 'GET',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='Shipment',  # 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 get_shipments(self, status, **kwargs):  # noqa: E501
        """get_shipments  # noqa: E501

        Get a list of shipments created for the seller in the status you specify. Shipments can be further filtered based on the fulfillment node or the time of the shipments' last update.  # 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_shipments(status, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str status: The status of shipment you want to include in the response. To retrieve all new shipments, set this value to `ACCEPTED`. (required)
        :param str location_id: The Amazon channel location identifier for the shipments you want to retrieve.
        :param str marketplace_id: The marketplace ID associated with the location. To find the ID for your marketplace, refer to [Marketplace IDs](https://developer-docs.amazon.com/sp-api/docs/marketplace-ids).
        :param str channel_name: The channel name associated with the location.
        :param str last_updated_after: The response includes shipments whose latest update is after the specified time. In [ISO 8601](https://developer-docs.amazon.com/sp-api/docs/iso-8601) date-time format.
        :param str last_updated_before: The response includes shipments whose latest update is before the specified time. In [ISO 8601](https://developer-docs.amazon.com/sp-api/docs/iso-8601) date-time format.
        :param int max_results: The maximum number of shipments to include in the response.
        :param str pagination_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: ShipmentsResponse
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.get_shipments_with_http_info(status, **kwargs)  # noqa: E501
        else:
            (data) = self.get_shipments_with_http_info(status, **kwargs)  # noqa: E501
            return data

    def get_shipments_with_http_info(self, status, **kwargs):  # noqa: E501
        """get_shipments  # noqa: E501

        Get a list of shipments created for the seller in the status you specify. Shipments can be further filtered based on the fulfillment node or the time of the shipments' last update.  # 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_shipments_with_http_info(status, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str status: The status of shipment you want to include in the response. To retrieve all new shipments, set this value to `ACCEPTED`. (required)
        :param str location_id: The Amazon channel location identifier for the shipments you want to retrieve.
        :param str marketplace_id: The marketplace ID associated with the location. To find the ID for your marketplace, refer to [Marketplace IDs](https://developer-docs.amazon.com/sp-api/docs/marketplace-ids).
        :param str channel_name: The channel name associated with the location.
        :param str last_updated_after: The response includes shipments whose latest update is after the specified time. In [ISO 8601](https://developer-docs.amazon.com/sp-api/docs/iso-8601) date-time format.
        :param str last_updated_before: The response includes shipments whose latest update is before the specified time. In [ISO 8601](https://developer-docs.amazon.com/sp-api/docs/iso-8601) date-time format.
        :param int max_results: The maximum number of shipments to include in the response.
        :param str pagination_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: ShipmentsResponse
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['status', 'location_id', 'marketplace_id', 'channel_name', 'last_updated_after', 'last_updated_before', 'max_results', 'pagination_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 get_shipments" % key
                )
            params[key] = val
        del params['kwargs']
        # verify the required parameter 'status' is set
        if self.api_client.client_side_validation and ('status' not in params or
                                                       params['status'] is None):  # noqa: E501
            raise ValueError("Missing the required parameter `status` when calling `get_shipments`")  # noqa: E501

        if self.api_client.client_side_validation and ('location_id' in params and
                                                       len(params['location_id']) > 36):
            raise ValueError("Invalid value for parameter `location_id` when calling `get_shipments`, length must be less than or equal to `36`")  # noqa: E501
        if self.api_client.client_side_validation and ('channel_name' in params and
                                                       len(params['channel_name']) > 10):
            raise ValueError("Invalid value for parameter `channel_name` when calling `get_shipments`, length must be less than or equal to `10`")  # noqa: E501
        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 `get_shipments`, must be a value less than or equal to `100`")  # noqa: E501
        if self.api_client.client_side_validation and ('max_results' in params and params['max_results'] < 1):  # noqa: E501
            raise ValueError("Invalid value for parameter `max_results` when calling `get_shipments`, must be a value greater than or equal to `1`")  # noqa: E501
        collection_formats = {}

        path_params = {}

        query_params = []
        if 'location_id' in params:
            query_params.append(('locationId', params['location_id']))  # noqa: E501
        if 'marketplace_id' in params:
            query_params.append(('marketplaceId', params['marketplace_id']))  # noqa: E501
        if 'channel_name' in params:
            query_params.append(('channelName', params['channel_name']))  # noqa: E501
        if 'status' in params:
            query_params.append(('status', params['status']))  # 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 'pagination_token' in params:
            query_params.append(('paginationToken', params['pagination_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/shipments', 'GET',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='ShipmentsResponse',  # 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)
