<?php

namespace Tops\AmazonSellingPartnerAPI\Api;

class ListingsRestrictions extends BaseApi
{
    /**
     * Operation Get Item Eligibility Preview
     *
     * @param string|array $params['marketplaceIds'] he identifier for the marketplace in which you want to determine eligibility. (required).
     * @param string $params['asin'] The ASIN of the item for which you want an eligibility preview. (required)
     * @return json\
     * @author Jignesh Kapadia <jignesh@topsinfosolutions.com>
     * about more Ref: https://developer-docs.amazon.com/sp-api/docs/listings-restrictions-api-v2021-08-01-reference
     */
    public function getListingsRestrictions($params)
    {
        if (!array_key_exists('asin', $params) || empty($params['asin'])) {
            throw new \InvalidArgumentException('Missing the required parameter $asin when calling getListingsRestrictions');
        }

        if (!array_key_exists('sellerId', $params) || empty($params['sellerId'])) {
            throw new \InvalidArgumentException('Missing the required parameter $sellerId when calling getListingsRestrictions');
        }

        if (!array_key_exists('marketplaceIds', $params) || empty($params['marketplaceIds'])) {
            throw new \InvalidArgumentException('Missing the required parameter $marketplaceIds when calling getListingsRestrictions');
        }

        $resource_path = '/listings/2021-08-01/restrictions';
        $url = $this->config->getHost() . $resource_path;
        $http_body = '';
        $query_params = [];
        $method = 'GET';

        // query params
        if (array_key_exists('marketplaceIds', $params) && !empty($params['marketplaceIds'])) {
            $query_params['marketplaceIds'] = is_array($params['marketplaceIds']) ? implode(',', $params['marketplaceIds']) :  $params['marketplaceIds'];
        }

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

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

        if (array_key_exists('conditionType', $params) && !empty($params['conditionType'])) {
            $query_params['conditionType'] = $params['conditionType'];
        }
        else {
            $query_params['conditionType'] = "new_new";
        }

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

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