/*
 * Selling Partner API for Product Type Definitions
 * The Selling Partner API for Product Type Definitions provides programmatic access to attribute and data requirements for product types in the Amazon catalog. Use this API to return the JSON Schema for a product type that you can then use with other Selling Partner APIs, such as the Selling Partner API for Listings Items, the Selling Partner API for Catalog Items, and the Selling Partner API for Feeds (for JSON-based listing feeds).  For more information, see the [Product Type Definitions API Use Case Guide](doc:product-type-api-use-case-guide).
 *
 * OpenAPI spec version: 2020-09-01
 *
 * NOTE: This class is auto generated by the swagger code generator program.
 * https://github.com/swagger-api/swagger-codegen.git
 *
 * Swagger Codegen version: 2.4.9
 *
 * Do not edit the class manually.
 *
 */

import { ApiClient } from "../ApiClient.js";
import { ErrorList } from "../js-client.definitionsProductTypes_2020-09-01.model/ErrorList.js";
import { ProductTypeDefinition } from "../js-client.definitionsProductTypes_2020-09-01.model/ProductTypeDefinition.js";
import { ProductTypeList } from "../js-client.definitionsProductTypes_2020-09-01.model/ProductTypeList.js";
import { HEADER_DATA } from "../../constants/global";

/**
 * Definitions service.
 * @module definitionsProductTypes_2020-09-01/js-client.definitionsProductTypes_2020-09-01.api/DefinitionsApi
 * @version 2020-09-01
 */
export class DefinitionsApi {
  /**
   * Constructs a new DefinitionsApi.
   * @alias module:definitionsProductTypes_2020-09-01/js-client.definitionsProductTypes_2020-09-01.api/DefinitionsApi
   * @class
   * @param {module:definitionsProductTypes_2020-09-01/ApiClient} [apiClient] Optional API client implementation to use,
   * default to {@link module:definitionsProductTypes_2020-09-01/ApiClient#instance} if unspecified.
   */
  constructor(apiClient) {
    this.apiClient = apiClient || ApiClient.instance;
  }

  /**
   * Retrieve an Amazon product type definition.  **Usage Plans:**  | Plan type | Rate (requests per second) | Burst | | ---- | ---- | ---- | |Default| 5 | 10 | |Selling partner specific| Variable | Variable |  The x-amzn-RateLimit-Limit response header returns the usage plan rate limits that were applied to the requested operation. Rate limits for some selling partners will vary from the default rate and burst shown in the table above. For more information, see [Usage Plans and Rate Limits in the Selling Partner API](doc:usage-plans-and-rate-limits-in-the-sp-api).
   * @param {String} productType The Amazon product type name.
   * @param {Array.<String>} marketplaceIds A comma-delimited list of Amazon marketplace identifiers for the request. Note: This parameter is limited to one marketplaceId at this time.
   * @param {Object} opts Optional parameters
   * @param {String} opts.sellerId A selling partner identifier. When provided, seller-specific requirements and values are populated within the product type definition schema, such as brand names associated with the selling partner.
   * @param {String} opts.productTypeVersion The version of the Amazon product type to retrieve. Defaults to \"LATEST\",. Prerelease versions of product type definitions may be retrieved with \"RELEASE_CANDIDATE\". If no prerelease version is currently available, the \"LATEST\" live version will be provided. (default to LATEST)
   * @param {module:definitionsProductTypes_2020-09-01/js-client.definitionsProductTypes_2020-09-01.model/String} opts.requirements The name of the requirements set to retrieve requirements for. (default to LISTING)
   * @param {module:definitionsProductTypes_2020-09-01/js-client.definitionsProductTypes_2020-09-01.model/String} opts.requirementsEnforced Identifies if the required attributes for a requirements set are enforced by the product type definition schema. Non-enforced requirements enable structural validation of individual attributes without all the required attributes being present (such as for partial updates). (default to ENFORCED)
   * @param {module:definitionsProductTypes_2020-09-01/js-client.definitionsProductTypes_2020-09-01.model/String} opts.locale Locale for retrieving display labels and other presentation details. Defaults to the default language of the first marketplace in the request. (default to DEFAULT)
   * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing data of type {@link module:definitionsProductTypes_2020-09-01/js-client.definitionsProductTypes_2020-09-01.model/ProductTypeDefinition} and HTTP response
   */
  getDefinitionsProductTypeWithHttpInfo(productType, marketplaceIds, opts) {
    opts = opts || {};
    let postBody = null;

    // verify the required parameter 'productType' is set
    if (productType === undefined || productType === null) {
      throw new Error(
        "Missing the required parameter 'productType' when calling getDefinitionsProductType",
      );
    }

    // verify the required parameter 'marketplaceIds' is set
    if (marketplaceIds === undefined || marketplaceIds === null) {
      throw new Error(
        "Missing the required parameter 'marketplaceIds' when calling getDefinitionsProductType",
      );
    }

    let pathParams = {
      productType: productType,
    };
    let queryParams = {
      sellerId: opts["sellerId"],
      marketplaceIds: this.apiClient.buildCollectionParam(
        marketplaceIds,
        "csv",
      ),
      productTypeVersion: opts["productTypeVersion"],
      requirements: opts["requirements"],
      requirementsEnforced: opts["requirementsEnforced"],
      locale: opts["locale"],
    };
    let headerParams = HEADER_DATA;
    let formParams = {};

    let contentTypes = ["application/json"];
    let accepts = ["application/json"];
    let returnType = ProductTypeDefinition;

    return this.apiClient.callApi(
      "/definitions/2020-09-01/productTypes/{productType}",
      "GET",
      pathParams,
      queryParams,
      headerParams,
      formParams,
      postBody,
      contentTypes,
      accepts,
      returnType,
    );
  }

  /**
   * Retrieve an Amazon product type definition.  **Usage Plans:**  | Plan type | Rate (requests per second) | Burst | | ---- | ---- | ---- | |Default| 5 | 10 | |Selling partner specific| Variable | Variable |  The x-amzn-RateLimit-Limit response header returns the usage plan rate limits that were applied to the requested operation. Rate limits for some selling partners will vary from the default rate and burst shown in the table above. For more information, see [Usage Plans and Rate Limits in the Selling Partner API](doc:usage-plans-and-rate-limits-in-the-sp-api).
   * @param {String} productType The Amazon product type name.
   * @param {Array.<String>} marketplaceIds A comma-delimited list of Amazon marketplace identifiers for the request. Note: This parameter is limited to one marketplaceId at this time.
   * @param {Object} opts Optional parameters
   * @param {String} opts.sellerId A selling partner identifier. When provided, seller-specific requirements and values are populated within the product type definition schema, such as brand names associated with the selling partner.
   * @param {String} opts.productTypeVersion The version of the Amazon product type to retrieve. Defaults to \"LATEST\",. Prerelease versions of product type definitions may be retrieved with \"RELEASE_CANDIDATE\". If no prerelease version is currently available, the \"LATEST\" live version will be provided. (default to LATEST)
   * @param {module:definitionsProductTypes_2020-09-01/js-client.definitionsProductTypes_2020-09-01.model/String} opts.requirements The name of the requirements set to retrieve requirements for. (default to LISTING)
   * @param {module:definitionsProductTypes_2020-09-01/js-client.definitionsProductTypes_2020-09-01.model/String} opts.requirementsEnforced Identifies if the required attributes for a requirements set are enforced by the product type definition schema. Non-enforced requirements enable structural validation of individual attributes without all the required attributes being present (such as for partial updates). (default to ENFORCED)
   * @param {module:definitionsProductTypes_2020-09-01/js-client.definitionsProductTypes_2020-09-01.model/String} opts.locale Locale for retrieving display labels and other presentation details. Defaults to the default language of the first marketplace in the request. (default to DEFAULT)
   * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with data of type {@link module:definitionsProductTypes_2020-09-01/js-client.definitionsProductTypes_2020-09-01.model/ProductTypeDefinition}
   */
  getDefinitionsProductType(productType, marketplaceIds, opts) {
    return this.getDefinitionsProductTypeWithHttpInfo(
      productType,
      marketplaceIds,
      opts,
    ).then(function (response_and_data) {
      return response_and_data.data;
    });
  }

  /**
   * Search for and return a list of Amazon product types that have definitions available.  **Usage Plans:**  | Plan type | Rate (requests per second) | Burst | | ---- | ---- | ---- | |Default| 5 | 10 | |Selling partner specific| Variable | Variable |  The x-amzn-RateLimit-Limit response header returns the usage plan rate limits that were applied to the requested operation. Rate limits for some selling partners will vary from the default rate and burst shown in the table above. For more information, see [Usage Plans and Rate Limits in the Selling Partner API](doc:usage-plans-and-rate-limits-in-the-sp-api).
   * @param {Array.<String>} marketplaceIds A comma-delimited list of Amazon marketplace identifiers for the request.
   * @param {Object} opts Optional parameters
   * @param {Array.<String>} opts.keywords A comma-delimited list of keywords to search product types by. **Note:** Cannot be used with `itemName`.
   * @param {String} opts.itemName The title of the ASIN to get the product type recommendation. **Note:** Cannot be used with `keywords`.
   * @param {String} opts.locale The locale for the display names in the response. Defaults to the primary locale of the marketplace.
   * @param {String} opts.searchLocale The locale used for the `keywords` and `itemName` parameters. Defaults to the primary locale of the marketplace.
   * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing data of type {@link module:definitionsProductTypes_2020-09-01/js-client.definitionsProductTypes_2020-09-01.model/ProductTypeList} and HTTP response
   */
  searchDefinitionsProductTypesWithHttpInfo(marketplaceIds, opts) {
    opts = opts || {};
    let postBody = null;

    // verify the required parameter 'marketplaceIds' is set
    if (marketplaceIds === undefined || marketplaceIds === null) {
      throw new Error(
        "Missing the required parameter 'marketplaceIds' when calling searchDefinitionsProductTypes",
      );
    }

    let pathParams = {};
    let queryParams = {
      keywords: this.apiClient.buildCollectionParam(opts["keywords"], "csv"),
      marketplaceIds: this.apiClient.buildCollectionParam(
        marketplaceIds,
        "csv",
      ),
      itemName: opts["itemName"],
      locale: opts["locale"],
      searchLocale: opts["searchLocale"],
    };
    let headerParams = HEADER_DATA;
    let formParams = {};

    let contentTypes = ["application/json"];
    let accepts = ["application/json"];
    let returnType = ProductTypeList;

    return this.apiClient.callApi(
      "/definitions/2020-09-01/productTypes",
      "GET",
      pathParams,
      queryParams,
      headerParams,
      formParams,
      postBody,
      contentTypes,
      accepts,
      returnType,
    );
  }

  /**
   * Search for and return a list of Amazon product types that have definitions available.  **Usage Plans:**  | Plan type | Rate (requests per second) | Burst | | ---- | ---- | ---- | |Default| 5 | 10 | |Selling partner specific| Variable | Variable |  The x-amzn-RateLimit-Limit response header returns the usage plan rate limits that were applied to the requested operation. Rate limits for some selling partners will vary from the default rate and burst shown in the table above. For more information, see [Usage Plans and Rate Limits in the Selling Partner API](doc:usage-plans-and-rate-limits-in-the-sp-api).
   * @param {Array.<String>} marketplaceIds A comma-delimited list of Amazon marketplace identifiers for the request.
   * @param {Object} opts Optional parameters
   * @param {Array.<String>} opts.keywords A comma-delimited list of keywords to search product types. **Note:** Cannot be used with `itemName`.
   * @param {String} opts.itemName The title of the ASIN to get the product type recommendation. **Note:** Cannot be used with `keywords`.
   * @param {String} opts.locale The locale for the display names in the response. Defaults to the primary locale of the marketplace.
   * @param {String} opts.searchLocale The locale used for the `keywords` and `itemName` parameters. Defaults to the primary locale of the marketplace.
   * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with data of type {@link module:definitionsProductTypes_2020-09-01/js-client.definitionsProductTypes_2020-09-01.model/ProductTypeList}
   */
  searchDefinitionsProductTypes(marketplaceIds, opts) {
    return this.searchDefinitionsProductTypesWithHttpInfo(
      marketplaceIds,
      opts,
    ).then(function (response_and_data) {
      return response_and_data.data;
    });
  }
}
