001
002package com.commercetools.api.client;
003
004import java.net.URI;
005import java.nio.charset.StandardCharsets;
006import java.time.Duration;
007import java.util.ArrayList;
008import java.util.Collection;
009import java.util.List;
010import java.util.concurrent.CompletableFuture;
011import java.util.function.Function;
012import java.util.function.Supplier;
013import java.util.stream.Collectors;
014
015import io.vrap.rmf.base.client.*;
016import io.vrap.rmf.base.client.utils.Generated;
017
018import org.apache.commons.lang3.builder.EqualsBuilder;
019import org.apache.commons.lang3.builder.HashCodeBuilder;
020
021/**
022 *  <p>To update a CartDiscount, you must have permissions for all Stores the CartDiscount is associated with, except when removing a Store.</p>
023 *
024 * <hr>
025 * <div class=code-example>
026 * <pre><code class='java'>{@code
027 *   CompletableFuture<ApiHttpResponse<com.commercetools.api.models.cart_discount.CartDiscount>> result = apiRoot
028 *            .withProjectKey("{projectKey}")
029 *            .inStoreKeyWithStoreKeyValue("{storeKey}")
030 *            .cartDiscounts()
031 *            .withKey("{key}")
032 *            .post("")
033 *            .execute()
034 * }</code></pre>
035 * </div>
036 */
037@Generated(value = "io.vrap.rmf.codegen.rendering.CoreCodeGenerator", comments = "https://github.com/commercetools/rmf-codegen")
038public class ByProjectKeyInStoreKeyByStoreKeyCartDiscountsKeyByKeyPostString extends
039        StringBodyApiMethod<ByProjectKeyInStoreKeyByStoreKeyCartDiscountsKeyByKeyPostString, com.commercetools.api.models.cart_discount.CartDiscount>
040        implements
041        com.commercetools.api.client.ConflictingTrait<ByProjectKeyInStoreKeyByStoreKeyCartDiscountsKeyByKeyPostString>,
042        com.commercetools.api.client.ExpandableTrait<ByProjectKeyInStoreKeyByStoreKeyCartDiscountsKeyByKeyPostString>,
043        com.commercetools.api.client.Deprecatable200Trait<ByProjectKeyInStoreKeyByStoreKeyCartDiscountsKeyByKeyPostString>,
044        com.commercetools.api.client.ErrorableTrait<ByProjectKeyInStoreKeyByStoreKeyCartDiscountsKeyByKeyPostString> {
045
046    private String projectKey;
047    private String storeKey;
048    private String key;
049
050    private String cartDiscountUpdate;
051
052    public ByProjectKeyInStoreKeyByStoreKeyCartDiscountsKeyByKeyPostString(final ApiHttpClient apiHttpClient,
053            String projectKey, String storeKey, String key, String cartDiscountUpdate) {
054        super(apiHttpClient);
055        this.projectKey = projectKey;
056        this.storeKey = storeKey;
057        this.key = key;
058        this.cartDiscountUpdate = cartDiscountUpdate;
059    }
060
061    public ByProjectKeyInStoreKeyByStoreKeyCartDiscountsKeyByKeyPostString(
062            ByProjectKeyInStoreKeyByStoreKeyCartDiscountsKeyByKeyPostString t) {
063        super(t);
064        this.projectKey = t.projectKey;
065        this.storeKey = t.storeKey;
066        this.key = t.key;
067        this.cartDiscountUpdate = t.cartDiscountUpdate;
068    }
069
070    @Override
071    protected ApiHttpRequest buildHttpRequest() {
072        List<String> params = new ArrayList<>(getQueryParamUriStrings());
073        String httpRequestPath = String.format("%s/in-store/key=%s/cart-discounts/key=%s", this.projectKey,
074            this.storeKey, this.key);
075        if (!params.isEmpty()) {
076            httpRequestPath += "?" + String.join("&", params);
077        }
078        return new ApiHttpRequest(ApiHttpMethod.POST, URI.create(httpRequestPath), getHeaders(),
079            cartDiscountUpdate.getBytes(StandardCharsets.UTF_8));
080
081    }
082
083    @Override
084    public ApiHttpResponse<com.commercetools.api.models.cart_discount.CartDiscount> executeBlocking(
085            final ApiHttpClient client, final Duration timeout) {
086        return executeBlocking(client, timeout, com.commercetools.api.models.cart_discount.CartDiscount.class);
087    }
088
089    @Override
090    public CompletableFuture<ApiHttpResponse<com.commercetools.api.models.cart_discount.CartDiscount>> execute(
091            final ApiHttpClient client) {
092        return execute(client, com.commercetools.api.models.cart_discount.CartDiscount.class);
093    }
094
095    public String getProjectKey() {
096        return this.projectKey;
097    }
098
099    public String getStoreKey() {
100        return this.storeKey;
101    }
102
103    public String getKey() {
104        return this.key;
105    }
106
107    public List<String> getExpand() {
108        return this.getQueryParam("expand");
109    }
110
111    public void setProjectKey(final String projectKey) {
112        this.projectKey = projectKey;
113    }
114
115    public void setStoreKey(final String storeKey) {
116        this.storeKey = storeKey;
117    }
118
119    public void setKey(final String key) {
120        this.key = key;
121    }
122
123    /**
124     * set expand with the specified value
125     * @param <TValue> value type
126     * @param expand value to be set
127     * @return ByProjectKeyInStoreKeyByStoreKeyCartDiscountsKeyByKeyPostString
128     */
129    public <TValue> ByProjectKeyInStoreKeyByStoreKeyCartDiscountsKeyByKeyPostString withExpand(final TValue expand) {
130        return copy().withQueryParam("expand", expand);
131    }
132
133    /**
134     * add additional expand query parameter
135     * @param <TValue> value type
136     * @param expand value to be added
137     * @return ByProjectKeyInStoreKeyByStoreKeyCartDiscountsKeyByKeyPostString
138     */
139    public <TValue> ByProjectKeyInStoreKeyByStoreKeyCartDiscountsKeyByKeyPostString addExpand(final TValue expand) {
140        return copy().addQueryParam("expand", expand);
141    }
142
143    /**
144     * set expand with the specified value
145     * @param supplier supplier for the value to be set
146     * @return ByProjectKeyInStoreKeyByStoreKeyCartDiscountsKeyByKeyPostString
147     */
148    public ByProjectKeyInStoreKeyByStoreKeyCartDiscountsKeyByKeyPostString withExpand(final Supplier<String> supplier) {
149        return copy().withQueryParam("expand", supplier.get());
150    }
151
152    /**
153     * add additional expand query parameter
154     * @param supplier supplier for the value to be added
155     * @return ByProjectKeyInStoreKeyByStoreKeyCartDiscountsKeyByKeyPostString
156     */
157    public ByProjectKeyInStoreKeyByStoreKeyCartDiscountsKeyByKeyPostString addExpand(final Supplier<String> supplier) {
158        return copy().addQueryParam("expand", supplier.get());
159    }
160
161    /**
162     * set expand with the specified value
163     * @param op builder for the value to be set
164     * @return ByProjectKeyInStoreKeyByStoreKeyCartDiscountsKeyByKeyPostString
165     */
166    public ByProjectKeyInStoreKeyByStoreKeyCartDiscountsKeyByKeyPostString withExpand(
167            final Function<StringBuilder, StringBuilder> op) {
168        return copy().withQueryParam("expand", op.apply(new StringBuilder()));
169    }
170
171    /**
172     * add additional expand query parameter
173     * @param op builder for the value to be added
174     * @return ByProjectKeyInStoreKeyByStoreKeyCartDiscountsKeyByKeyPostString
175     */
176    public ByProjectKeyInStoreKeyByStoreKeyCartDiscountsKeyByKeyPostString addExpand(
177            final Function<StringBuilder, StringBuilder> op) {
178        return copy().addQueryParam("expand", op.apply(new StringBuilder()));
179    }
180
181    /**
182     * set expand with the specified values
183     * @param <TValue> value type
184     * @param expand values to be set
185     * @return ByProjectKeyInStoreKeyByStoreKeyCartDiscountsKeyByKeyPostString
186     */
187    public <TValue> ByProjectKeyInStoreKeyByStoreKeyCartDiscountsKeyByKeyPostString withExpand(
188            final Collection<TValue> expand) {
189        return copy().withoutQueryParam("expand")
190                .addQueryParams(
191                    expand.stream().map(s -> new ParamEntry<>("expand", s.toString())).collect(Collectors.toList()));
192    }
193
194    /**
195     * add additional expand query parameters
196     * @param <TValue> value type
197     * @param expand values to be added
198     * @return ByProjectKeyInStoreKeyByStoreKeyCartDiscountsKeyByKeyPostString
199     */
200    public <TValue> ByProjectKeyInStoreKeyByStoreKeyCartDiscountsKeyByKeyPostString addExpand(
201            final Collection<TValue> expand) {
202        return copy().addQueryParams(
203            expand.stream().map(s -> new ParamEntry<>("expand", s.toString())).collect(Collectors.toList()));
204    }
205
206    public String getBody() {
207        return cartDiscountUpdate;
208    }
209
210    public ByProjectKeyInStoreKeyByStoreKeyCartDiscountsKeyByKeyPostString withBody(String cartDiscountUpdate) {
211        ByProjectKeyInStoreKeyByStoreKeyCartDiscountsKeyByKeyPostString t = copy();
212        t.cartDiscountUpdate = cartDiscountUpdate;
213        return t;
214    }
215
216    @Override
217    public boolean equals(Object o) {
218        if (this == o)
219            return true;
220
221        if (o == null || getClass() != o.getClass())
222            return false;
223
224        ByProjectKeyInStoreKeyByStoreKeyCartDiscountsKeyByKeyPostString that = (ByProjectKeyInStoreKeyByStoreKeyCartDiscountsKeyByKeyPostString) o;
225
226        return new EqualsBuilder().append(projectKey, that.projectKey)
227                .append(storeKey, that.storeKey)
228                .append(key, that.key)
229                .append(cartDiscountUpdate, that.cartDiscountUpdate)
230                .isEquals();
231    }
232
233    @Override
234    public int hashCode() {
235        return new HashCodeBuilder(17, 37).append(projectKey)
236                .append(storeKey)
237                .append(key)
238                .append(cartDiscountUpdate)
239                .toHashCode();
240    }
241
242    @Override
243    protected ByProjectKeyInStoreKeyByStoreKeyCartDiscountsKeyByKeyPostString copy() {
244        return new ByProjectKeyInStoreKeyByStoreKeyCartDiscountsKeyByKeyPostString(this);
245    }
246}