<?php

namespace Tops\AmazonSellingPartnerAPI\Api;

class ShippingApi extends BaseApi
{

    /**
     * Operation Crate Shipment
     *
     * @param array $body The request schema for the createShipment operation.
     *
     * @return json Create a new shipment.
     *
     * @author Chetan Meena <chetan@topsinfosolutions.com>
     *
     * About more Ref:- https://github.com/amzn/selling-partner-api-docs/blob/main/references/shipping-api/shipping.md#createshipment
     */
    public function createShipment($body)
    {
        if (null === $body) {
            throw new \InvalidArgumentException('Missing the required parameter $body when calling createShipment');
        }
        $resource_path = '/shipping/v1/shipments';
        $query_params = [];
        $http_body = $body;
        $method = 'POST';

        $curl_headers = $this->generateRequest($resource_path, $query_params, $http_body, $this->config, $method);

        $url = $this->config->getHost() . $resource_path;
        return $this->sendRequest($url, $query_params, $http_body, $curl_headers, $method);
    }

    /**
    * Operation Get Shipment
    *
    * @param string $shipment_id
    *
    * @author Chetan Meena <chetan@topsinfosolutions.com>
    *
    * @return
    *
    * About more Ref :- https://github.com/amzn/selling-partner-api-docs/blob/main/references/shipping-api/shipping.md#getshipment
    */
    public function getShipment($shipment_id)
    {
        if (null === $shipment_id) {
            throw new \InvalidArgumentException('Missing the required parameter $shipment_id when calling getShipment');
        }

        $resource_path = '/shipping/v1/shipments/{shipmentId}';
        $query_params = [];
        $http_body ='';
        $method = 'GET';

        // path params
        if (null !== $shipment_id) {
            $resource_path = str_replace(
                '{' . 'shipmentId' . '}',
                $shipment_id,
                $resource_path
            );
        }

        $curl_headers = $this->generateRequest($resource_path, $query_params, $http_body, $this->config, $method);

        $url = $this->config->getHost() . $resource_path;
        return $this->sendRequest($url, $query_params, $http_body, $curl_headers, $method);
    }

    /**
    * Operation Cancel Shipment
    *
    * @param string $shipment_id
    *
    * @return
    *
    *  @author Chetan Meena <chetan@topsinfosolutions.com>
    *
    * About more Ref :- https://github.com/amzn/selling-partner-api-docs/blob/main/references/shipping-api/shipping.md#cancelshipment
    */
    public function cancelShipment($shipment_id)
    {
        if (null === $shipment_id) {
            throw new \InvalidArgumentException('Missing the required parameter $shipment_id when calling getShipment');
        }
        $resource_path = '/shipping/v1/shipments/{shipmentId}/cancel';
        $query_params = [];
        $http_body ='';
        $method = 'POST';

        // path params
        if (null !== $shipment_id) {
            $resource_path = str_replace(
                '{' . 'shipmentId' . '}',
                $shipment_id,
                $resource_path
            );
        }

        $curl_headers = $this->generateRequest($resource_path, $query_params, $http_body, $this->config, $method);

        $url = $this->config->getHost() . $resource_path;
        return $this->sendRequest($url, $query_params, $http_body, $curl_headers, $method);
    }

    /**
    * Operation Purchase Lables
    *
    * @param array $body
    *
    * @param string $shipment_id
    *
    * @return
    *
    * @author Chetan Meena <chetan@topsinfosolutions.com>
    *
    * About more Ref :- https://github.com/amzn/selling-partner-api-docs/blob/main/references/shipping-api/shipping.md#purchaselabels
    */
    public function purchaseLabels($body, $shipment_id)
    {
        if (null === $shipment_id) {
            throw new \InvalidArgumentException('Missing the required parameter $shipment_id when calling purchaseLabels');
        }
        if (null === $body) {
            throw new \InvalidArgumentException('Missing the required parameter $body when calling purchaseLabels');
        }
        $resource_path = '/shipping/v1/shipments/{shipmentId}/purchaseLabels';
        $query_params = [];
        $http_body = $body;
        $method = 'POST';

        // path params
        if (null !== $shipment_id) {
            $resource_path = str_replace(
                '{' . 'shipmentId' . '}',
                $shipment_id,
                $resource_path
            );
        }

        $curl_headers = $this->generateRequest($resource_path, $query_params, $http_body, $this->config, $method);

        $url = $this->config->getHost() . $resource_path;
        return $this->sendRequest($url, $query_params, $http_body, $curl_headers, $method);
    }

    /**
     * Operation Retrieve Shipping Label
     *
     * @param array $body the request schema for the retrieveShippingLabel operation.     *
     * @param string $shipment_id
     * @param string $traking_id
     *
     * @return
     *
     * @author Chetan Meena <chetan@topsinfosolutions.com>
     *
     * About more Ref:- https://github.com/amzn/selling-partner-api-docs/blob/main/references/shipping-api/shipping.md#retrieveshippinglabel
     */
    public function retrieveShippingLabel($body, $shipment_id, $traking_id)
    {
        if (null === $shipment_id) {
            throw new \InvalidArgumentException('Missing the required parameter $shipment_id when calling retrieveShippingLabel');
        }
        if (null === $body) {
            throw new \InvalidArgumentException('Missing the required parameter $body when calling retrieveShippingLabel');
        }
        if (null === $traking_id) {
            throw new \InvalidArgumentException('Missing the required parameter $traking_id when calling retrieveShippingLabel');
        }
        $resource_path = '/shipping/v1/shipments/{shipmentId}/containers/{trackingId}/label';
        $query_params = [];
        $http_body = $body;
        $method = 'POST';

        // path params
        if (null !== $shipment_id) {
            $resource_path = str_replace(
                '{' . 'shipmentId' . '}',
                $shipment_id,
                $resource_path
            );
        }

        if (null !== $traking_id) {
            $resource_path = str_replace(
                '{' . 'trackingId' . '}',
                $traking_id,
                $resource_path
            );
        }

        $curl_headers = $this->generateRequest($resource_path, $query_params, $http_body, $this->config, $method);

        $url = $this->config->getHost() . $resource_path;
        return $this->sendRequest($url, $query_params, $http_body, $curl_headers, $method);
    }

    /**
    * Operation Purchase Shipment
    *
    * @param array $body The payload schema for the purchaseShipment operation.
    *
    * @return
    *
    * @author Chetan Meena <chetan@topsinfosolutions.com>
    *
    * About more Ref:-https://github.com/amzn/selling-partner-api-docs/blob/main/references/shipping-api/shipping.md#purchaseshipment
    */
    public function purchaseShipment($body)
    {
        if (null === $body) {
            throw new \InvalidArgumentException('Missing the required parameter $body when calling retrieveShippingLabel');
        }

        $resource_path = '/shipping/v1/purchaseShipment';
        $query_params = [];
        $http_body = $body;
        $method = 'POST';
        
        $curl_headers = $this->generateRequest($resource_path, $query_params, $http_body, $this->config, $method);

        $url = $this->config->getHost() . $resource_path;
        return $this->sendRequest($url, $query_params, $http_body, $curl_headers, $method);
    }

    /**
     * Operation Get Rates
     *
     * @param array $body The payload schema for the getRates operation.
     *
     * @return
     *
     *  @author Chetan Meena <chetan@topsinfosolutions.com>
     *
     * About more Ref :- https://github.com/amzn/selling-partner-api-docs/blob/main/references/shipping-api/shipping.md#getrates
     */
    public function getRates($body)
    {
        if (null === $body) {
            throw new \InvalidArgumentException('Missing the required parameter $body when calling getRates');
        }
        $resource_path = '/shipping/v1/rates';
        $query_params = [];
        $http_body = $body;
        $method = 'POST';
        
        $curl_headers = $this->generateRequest($resource_path, $query_params, $http_body, $this->config, $method);

        $url = $this->config->getHost() . $resource_path;
        return $this->sendRequest($url, $query_params, $http_body, $curl_headers, $method);
    }

    /**
     * Operation Get Account
     *
     * @return
     *
     * @author Chetan Meena <chetan@topsinfosolutions.com>
     *
     * About more Ref :- https://github.com/amzn/selling-partner-api-docs/blob/main/references/shipping-api/shipping.md#getaccount
     */
    public function getAccount()
    {
        $resource_path = '/shipping/v1/account';
        $query_params = [];
        $http_body = '';
        $method = 'GET';
        
        $curl_headers = $this->generateRequest($resource_path, $query_params, $http_body, $this->config, $method);

        $url = $this->config->getHost() . $resource_path;
        return $this->sendRequest($url, $query_params, $http_body, $curl_headers, $method);
    }

    /**
     * Operation Get Tracking Information
     *
     * @param string $traking_id
     *
     * @return
     *
     * @author Chetan Meena <chetan@topsinfosolutions.com>
     *
     * About more Ref :- https://github.com/amzn/selling-partner-api-docs/blob/main/references/shipping-api/shipping.md#gettrackinginformation
     */
    public function getTrackingInformation($traking_id)
    {
        $resource_path = '/shipping/v1/tracking/{trackingId}';
        $query_params = [];
        $http_body = '';
        $method = 'GET';

        if (null !== $traking_id) {
            $resource_path = str_replace(
                '{' . 'trackingId' . '}',
                $traking_id,
                $resource_path
            );
        }

        $curl_headers = $this->generateRequest($resource_path, $query_params, $http_body, $this->config, $method);

        $url = $this->config->getHost() . $resource_path;
        return $this->sendRequest($url, $query_params, $http_body, $curl_headers, $method);
    }
}
