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 *
023 *
024 * <hr>
025 * <div class=code-example>
026 * <pre><code class='java'>{@code
027 *   CompletableFuture<ApiHttpResponse<com.commercetools.api.models.store.Store>> result = apiRoot
028 *            .withProjectKey("{projectKey}")
029 *            .stores()
030 *            .post("")
031 *            .execute()
032 * }</code></pre>
033 * </div>
034 */
035@Generated(value = "io.vrap.rmf.codegen.rendering.CoreCodeGenerator", comments = "https://github.com/commercetools/rmf-codegen")
036public class ByProjectKeyStoresPostString
037        extends StringBodyApiMethod<ByProjectKeyStoresPostString, com.commercetools.api.models.store.Store>
038        implements com.commercetools.api.client.ExpandableTrait<ByProjectKeyStoresPostString>,
039        com.commercetools.api.client.Deprecatable201Trait<ByProjectKeyStoresPostString>,
040        com.commercetools.api.client.ErrorableTrait<ByProjectKeyStoresPostString> {
041
042    private String projectKey;
043
044    private String storeDraft;
045
046    public ByProjectKeyStoresPostString(final ApiHttpClient apiHttpClient, String projectKey, String storeDraft) {
047        super(apiHttpClient);
048        this.projectKey = projectKey;
049        this.storeDraft = storeDraft;
050    }
051
052    public ByProjectKeyStoresPostString(ByProjectKeyStoresPostString t) {
053        super(t);
054        this.projectKey = t.projectKey;
055        this.storeDraft = t.storeDraft;
056    }
057
058    @Override
059    protected ApiHttpRequest buildHttpRequest() {
060        List<String> params = new ArrayList<>(getQueryParamUriStrings());
061        String httpRequestPath = String.format("%s/stores", this.projectKey);
062        if (!params.isEmpty()) {
063            httpRequestPath += "?" + String.join("&", params);
064        }
065        return new ApiHttpRequest(ApiHttpMethod.POST, URI.create(httpRequestPath), getHeaders(),
066            storeDraft.getBytes(StandardCharsets.UTF_8));
067
068    }
069
070    @Override
071    public ApiHttpResponse<com.commercetools.api.models.store.Store> executeBlocking(final ApiHttpClient client,
072            final Duration timeout) {
073        return executeBlocking(client, timeout, com.commercetools.api.models.store.Store.class);
074    }
075
076    @Override
077    public CompletableFuture<ApiHttpResponse<com.commercetools.api.models.store.Store>> execute(
078            final ApiHttpClient client) {
079        return execute(client, com.commercetools.api.models.store.Store.class);
080    }
081
082    public String getProjectKey() {
083        return this.projectKey;
084    }
085
086    public List<String> getExpand() {
087        return this.getQueryParam("expand");
088    }
089
090    public void setProjectKey(final String projectKey) {
091        this.projectKey = projectKey;
092    }
093
094    /**
095     * set expand with the specified value
096     * @param <TValue> value type
097     * @param expand value to be set
098     * @return ByProjectKeyStoresPostString
099     */
100    public <TValue> ByProjectKeyStoresPostString withExpand(final TValue expand) {
101        return copy().withQueryParam("expand", expand);
102    }
103
104    /**
105     * add additional expand query parameter
106     * @param <TValue> value type
107     * @param expand value to be added
108     * @return ByProjectKeyStoresPostString
109     */
110    public <TValue> ByProjectKeyStoresPostString addExpand(final TValue expand) {
111        return copy().addQueryParam("expand", expand);
112    }
113
114    /**
115     * set expand with the specified value
116     * @param supplier supplier for the value to be set
117     * @return ByProjectKeyStoresPostString
118     */
119    public ByProjectKeyStoresPostString withExpand(final Supplier<String> supplier) {
120        return copy().withQueryParam("expand", supplier.get());
121    }
122
123    /**
124     * add additional expand query parameter
125     * @param supplier supplier for the value to be added
126     * @return ByProjectKeyStoresPostString
127     */
128    public ByProjectKeyStoresPostString addExpand(final Supplier<String> supplier) {
129        return copy().addQueryParam("expand", supplier.get());
130    }
131
132    /**
133     * set expand with the specified value
134     * @param op builder for the value to be set
135     * @return ByProjectKeyStoresPostString
136     */
137    public ByProjectKeyStoresPostString withExpand(final Function<StringBuilder, StringBuilder> op) {
138        return copy().withQueryParam("expand", op.apply(new StringBuilder()));
139    }
140
141    /**
142     * add additional expand query parameter
143     * @param op builder for the value to be added
144     * @return ByProjectKeyStoresPostString
145     */
146    public ByProjectKeyStoresPostString addExpand(final Function<StringBuilder, StringBuilder> op) {
147        return copy().addQueryParam("expand", op.apply(new StringBuilder()));
148    }
149
150    /**
151     * set expand with the specified values
152     * @param <TValue> value type
153     * @param expand values to be set
154     * @return ByProjectKeyStoresPostString
155     */
156    public <TValue> ByProjectKeyStoresPostString withExpand(final Collection<TValue> expand) {
157        return copy().withoutQueryParam("expand")
158                .addQueryParams(
159                    expand.stream().map(s -> new ParamEntry<>("expand", s.toString())).collect(Collectors.toList()));
160    }
161
162    /**
163     * add additional expand query parameters
164     * @param <TValue> value type
165     * @param expand values to be added
166     * @return ByProjectKeyStoresPostString
167     */
168    public <TValue> ByProjectKeyStoresPostString addExpand(final Collection<TValue> expand) {
169        return copy().addQueryParams(
170            expand.stream().map(s -> new ParamEntry<>("expand", s.toString())).collect(Collectors.toList()));
171    }
172
173    public String getBody() {
174        return storeDraft;
175    }
176
177    public ByProjectKeyStoresPostString withBody(String storeDraft) {
178        ByProjectKeyStoresPostString t = copy();
179        t.storeDraft = storeDraft;
180        return t;
181    }
182
183    @Override
184    public boolean equals(Object o) {
185        if (this == o)
186            return true;
187
188        if (o == null || getClass() != o.getClass())
189            return false;
190
191        ByProjectKeyStoresPostString that = (ByProjectKeyStoresPostString) o;
192
193        return new EqualsBuilder().append(projectKey, that.projectKey).append(storeDraft, that.storeDraft).isEquals();
194    }
195
196    @Override
197    public int hashCode() {
198        return new HashCodeBuilder(17, 37).append(projectKey).append(storeDraft).toHashCode();
199    }
200
201    @Override
202    protected ByProjectKeyStoresPostString copy() {
203        return new ByProjectKeyStoresPostString(this);
204    }
205}