001 002package com.commercetools.api.client; 003 004import java.net.URI; 005import java.time.Duration; 006import java.util.ArrayList; 007import java.util.List; 008import java.util.concurrent.CompletableFuture; 009 010import io.vrap.rmf.base.client.*; 011import io.vrap.rmf.base.client.utils.Generated; 012 013import org.apache.commons.lang3.builder.EqualsBuilder; 014import org.apache.commons.lang3.builder.HashCodeBuilder; 015 016/** 017 * <p>This endpoint can be used to simulate which Product Discounts would be applied if a specified Product Variant had a specified Price. Given Product and Product Variant IDs and a Price, this endpoint will return the ProductDiscount that would have been applied to that Price.</p> 018 * <p>If a Product Discount could not be found that could be applied to the Price of a Product Variant, a NoMatchingProductDiscountFound error is returned.</p> 019 * 020 * <hr> 021 * <div class=code-example> 022 * <pre><code class='java'>{@code 023 * CompletableFuture<ApiHttpResponse<com.commercetools.api.models.product_discount.ProductDiscount>> result = apiRoot 024 * .withProjectKey("{projectKey}") 025 * .productDiscounts() 026 * .matching() 027 * .post(null) 028 * .execute() 029 * }</code></pre> 030 * </div> 031 */ 032@Generated(value = "io.vrap.rmf.codegen.rendering.CoreCodeGenerator", comments = "https://github.com/commercetools/rmf-codegen") 033public class ByProjectKeyProductDiscountsMatchingPost extends 034 BodyApiMethod<ByProjectKeyProductDiscountsMatchingPost, com.commercetools.api.models.product_discount.ProductDiscount, com.commercetools.api.models.product_discount.ProductDiscountMatchQuery> 035 implements com.commercetools.api.client.ErrorableTrait<ByProjectKeyProductDiscountsMatchingPost> { 036 037 private String projectKey; 038 039 private com.commercetools.api.models.product_discount.ProductDiscountMatchQuery productDiscountMatchQuery; 040 041 public ByProjectKeyProductDiscountsMatchingPost(final ApiHttpClient apiHttpClient, String projectKey, 042 com.commercetools.api.models.product_discount.ProductDiscountMatchQuery productDiscountMatchQuery) { 043 super(apiHttpClient); 044 this.projectKey = projectKey; 045 this.productDiscountMatchQuery = productDiscountMatchQuery; 046 } 047 048 public ByProjectKeyProductDiscountsMatchingPost(ByProjectKeyProductDiscountsMatchingPost t) { 049 super(t); 050 this.projectKey = t.projectKey; 051 this.productDiscountMatchQuery = t.productDiscountMatchQuery; 052 } 053 054 @Override 055 protected ApiHttpRequest buildHttpRequest() { 056 List<String> params = new ArrayList<>(getQueryParamUriStrings()); 057 String httpRequestPath = String.format("%s/product-discounts/matching", this.projectKey); 058 if (!params.isEmpty()) { 059 httpRequestPath += "?" + String.join("&", params); 060 } 061 return new ApiHttpRequest(ApiHttpMethod.POST, URI.create(httpRequestPath), getHeaders(), 062 io.vrap.rmf.base.client.utils.json.JsonUtils.executing( 063 () -> apiHttpClient().getSerializerService().toJsonByteArray(productDiscountMatchQuery))); 064 065 } 066 067 @Override 068 public ApiHttpResponse<com.commercetools.api.models.product_discount.ProductDiscount> executeBlocking( 069 final ApiHttpClient client, final Duration timeout) { 070 return executeBlocking(client, timeout, com.commercetools.api.models.product_discount.ProductDiscount.class); 071 } 072 073 @Override 074 public CompletableFuture<ApiHttpResponse<com.commercetools.api.models.product_discount.ProductDiscount>> execute( 075 final ApiHttpClient client) { 076 return execute(client, com.commercetools.api.models.product_discount.ProductDiscount.class); 077 } 078 079 public String getProjectKey() { 080 return this.projectKey; 081 } 082 083 public void setProjectKey(final String projectKey) { 084 this.projectKey = projectKey; 085 } 086 087 public com.commercetools.api.models.product_discount.ProductDiscountMatchQuery getBody() { 088 return productDiscountMatchQuery; 089 } 090 091 public ByProjectKeyProductDiscountsMatchingPost withBody( 092 com.commercetools.api.models.product_discount.ProductDiscountMatchQuery productDiscountMatchQuery) { 093 ByProjectKeyProductDiscountsMatchingPost t = copy(); 094 t.productDiscountMatchQuery = productDiscountMatchQuery; 095 return t; 096 } 097 098 @Override 099 public boolean equals(Object o) { 100 if (this == o) 101 return true; 102 103 if (o == null || getClass() != o.getClass()) 104 return false; 105 106 ByProjectKeyProductDiscountsMatchingPost that = (ByProjectKeyProductDiscountsMatchingPost) o; 107 108 return new EqualsBuilder().append(projectKey, that.projectKey) 109 .append(productDiscountMatchQuery, that.productDiscountMatchQuery) 110 .isEquals(); 111 } 112 113 @Override 114 public int hashCode() { 115 return new HashCodeBuilder(17, 37).append(projectKey).append(productDiscountMatchQuery).toHashCode(); 116 } 117 118 @Override 119 protected ByProjectKeyProductDiscountsMatchingPost copy() { 120 return new ByProjectKeyProductDiscountsMatchingPost(this); 121 } 122}