<?php

namespace Tops\AmazonSellingPartnerAPI\Api;

class VendorShipmentsApi extends BaseApi
{
    /**
    * Operation Submit Shipment Confirmations
    *
    * @param array $body required
    *
    * @return json
    *
    * @author Jignesh Kapadia <jignesh@topsinfosolutions.com>
    *
    * About more Ref :- https://developer-docs.amazon.com/sp-api/docs/vendor-shipments-api-v1-reference#post-vendorshippingv1shipmentconfirmations
    */
    public function SubmitShipmentConfirmations($body)
    {
        $resource_path = '/vendor/shipping/v1/shipmentConfirmations';
        $http_body = $body;
        $query_params = [];
        $method = 'POST';

        $url = $this->config->getHost() . $resource_path;

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

        return $this->sendRequest($url, $query_params, $http_body, $curl_headers, $method);
    }

    /**
    * Get Shipment Details
    *
    * @param array $params array of input params
    * @param string $params['limit'] The limit to the number of records returned. Default value is 100 records.
    * @param string $params['nextToken']  	A string token returned in the response of your previous request.
    *
    * @return Json
    *
    * @author Jignesh Kapadia <jignesh@topsinfosolutions.com>
    *
    * About more Ref:- https://developer-docs.amazon.com/sp-api/docs/vendor-shipments-api-v1-reference#get-vendorshippingv1shipments
    */

    public function GetShipmentDetails(array $params)
    {
        $resource_path = '/vendor/shipping/v1/shipments';
       
        $url = $this->config->getHost() . $resource_path;
        $http_body = '';
        $query_params = [];
        $method = 'GET';

        if (array_key_exists('limit', $params) && !empty($params['limit'])) {
            $query_params['limit'] = $params['limit'];
        }

        if (array_key_exists('createdAfter', $params) && !empty($params['createdAfter'])) {
            $query_params['createdAfter'] = $params['createdAfter'];
        }

        if (array_key_exists('createdBefore', $params) && !empty($params['createdBefore'])) {
            $query_params['createdBefore'] = $params['createdBefore'];
        }

        if (array_key_exists('shipmentConfirmedBefore', $params) && !empty($params['shipmentConfirmedBefore'])) {
            $query_params['shipmentConfirmedBefore'] = $params['shipmentConfirmedBefore'];
        }

        if (array_key_exists('shipmentConfirmedAfter', $params) && !empty($params['shipmentConfirmedAfter'])) {
            $query_params['shipmentConfirmedAfter'] = $params['shipmentConfirmedAfter'];
        }

        if (array_key_exists('shippedBefore', $params) && !empty($params['shippedBefore'])) {
            $query_params['shippedBefore'] = $params['shippedBefore'];
        }

        if (array_key_exists('shippedAfter', $params) && !empty($params['shippedAfter'])) {
            $query_params['shippedAfter'] = $params['shippedAfter'];
        }

        if (array_key_exists('currentShipmentStatus', $params) && !empty($params['currentShipmentStatus'])) {
            $query_params['currentShipmentStatus'] = $params['currentShipmentStatus'];
        }

        if (array_key_exists('vendorShipmentIdentifier', $params) && !empty($params['vendorShipmentIdentifier'])) {
            $query_params['vendorShipmentIdentifier'] = $params['vendorShipmentIdentifier'];
        }

        if (array_key_exists('buyerWarehouseCode', $params) && !empty($params['buyerWarehouseCode'])) {
            $query_params['buyerWarehouseCode'] = $params['buyerWarehouseCode'];
        }

        if (array_key_exists('sellerWarehouseCode', $params) && !empty($params['sellerWarehouseCode'])) {
            $query_params['sellerWarehouseCode'] = $params['sellerWarehouseCode'];
        }

        if (array_key_exists('nextToken', $params) && !empty($params['nextToken'])) {
            $query_params['nextToken'] = $params['nextToken'];
        }

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

        return $this->sendRequest($url, $query_params, $http_body, $curl_headers, $method);
    }

    /**
    * Operation Submit Shipment Confirmations
    *
    * @param array $body required
    *
    * @return json
    *
    * @author Jignesh Kapadia <jignesh@topsinfosolutions.com>
    *
    * About more Ref :- https://developer-docs.amazon.com/sp-api/docs/vendor-shipments-api-v1-reference#post-vendorshippingv1shipments
    */
    public function SubmitShipments($body)
    {
        $resource_path = '/vendor/shipping/v1/shipments';
        $http_body = $body;
        $query_params = [];
        $method = 'POST';

        $url = $this->config->getHost() . $resource_path;

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

        return $this->sendRequest($url, $query_params, $http_body, $curl_headers, $method);
    }
}
