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