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>Authenticates a Customer associated with a Store. For more information, see Global versus Store-specific Customers.</p>
018 *  <p>If the Customer exists in the Project but the <code>stores</code> field references a different Store, this method returns an InvalidCredentials error.</p>
019 *
020 * <hr>
021 * <div class=code-example>
022 * <pre><code class='java'>{@code
023 *   CompletableFuture<ApiHttpResponse<com.commercetools.api.models.customer.CustomerSignInResult>> result = apiRoot
024 *            .withProjectKey("{projectKey}")
025 *            .inStoreKeyWithStoreKeyValue("{storeKey}")
026 *            .login()
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 ByProjectKeyInStoreKeyByStoreKeyLoginPost extends
034        BodyApiMethod<ByProjectKeyInStoreKeyByStoreKeyLoginPost, com.commercetools.api.models.customer.CustomerSignInResult, com.commercetools.api.models.customer.CustomerSignin>
035        implements com.commercetools.api.client.ErrorableTrait<ByProjectKeyInStoreKeyByStoreKeyLoginPost> {
036
037    private String projectKey;
038    private String storeKey;
039
040    private com.commercetools.api.models.customer.CustomerSignin customerSignin;
041
042    public ByProjectKeyInStoreKeyByStoreKeyLoginPost(final ApiHttpClient apiHttpClient, String projectKey,
043            String storeKey, com.commercetools.api.models.customer.CustomerSignin customerSignin) {
044        super(apiHttpClient);
045        this.projectKey = projectKey;
046        this.storeKey = storeKey;
047        this.customerSignin = customerSignin;
048    }
049
050    public ByProjectKeyInStoreKeyByStoreKeyLoginPost(ByProjectKeyInStoreKeyByStoreKeyLoginPost t) {
051        super(t);
052        this.projectKey = t.projectKey;
053        this.storeKey = t.storeKey;
054        this.customerSignin = t.customerSignin;
055    }
056
057    @Override
058    protected ApiHttpRequest buildHttpRequest() {
059        List<String> params = new ArrayList<>(getQueryParamUriStrings());
060        String httpRequestPath = String.format("%s/in-store/key=%s/login", this.projectKey, this.storeKey);
061        if (!params.isEmpty()) {
062            httpRequestPath += "?" + String.join("&", params);
063        }
064        return new ApiHttpRequest(ApiHttpMethod.POST, URI.create(httpRequestPath), getHeaders(),
065            io.vrap.rmf.base.client.utils.json.JsonUtils
066                    .executing(() -> apiHttpClient().getSerializerService().toJsonByteArray(customerSignin)));
067
068    }
069
070    @Override
071    public ApiHttpResponse<com.commercetools.api.models.customer.CustomerSignInResult> executeBlocking(
072            final ApiHttpClient client, final Duration timeout) {
073        return executeBlocking(client, timeout, com.commercetools.api.models.customer.CustomerSignInResult.class);
074    }
075
076    @Override
077    public CompletableFuture<ApiHttpResponse<com.commercetools.api.models.customer.CustomerSignInResult>> execute(
078            final ApiHttpClient client) {
079        return execute(client, com.commercetools.api.models.customer.CustomerSignInResult.class);
080    }
081
082    public String getProjectKey() {
083        return this.projectKey;
084    }
085
086    public String getStoreKey() {
087        return this.storeKey;
088    }
089
090    public void setProjectKey(final String projectKey) {
091        this.projectKey = projectKey;
092    }
093
094    public void setStoreKey(final String storeKey) {
095        this.storeKey = storeKey;
096    }
097
098    public com.commercetools.api.models.customer.CustomerSignin getBody() {
099        return customerSignin;
100    }
101
102    public ByProjectKeyInStoreKeyByStoreKeyLoginPost withBody(
103            com.commercetools.api.models.customer.CustomerSignin customerSignin) {
104        ByProjectKeyInStoreKeyByStoreKeyLoginPost t = copy();
105        t.customerSignin = customerSignin;
106        return t;
107    }
108
109    @Override
110    public boolean equals(Object o) {
111        if (this == o)
112            return true;
113
114        if (o == null || getClass() != o.getClass())
115            return false;
116
117        ByProjectKeyInStoreKeyByStoreKeyLoginPost that = (ByProjectKeyInStoreKeyByStoreKeyLoginPost) o;
118
119        return new EqualsBuilder().append(projectKey, that.projectKey)
120                .append(storeKey, that.storeKey)
121                .append(customerSignin, that.customerSignin)
122                .isEquals();
123    }
124
125    @Override
126    public int hashCode() {
127        return new HashCodeBuilder(17, 37).append(projectKey).append(storeKey).append(customerSignin).toHashCode();
128    }
129
130    @Override
131    protected ByProjectKeyInStoreKeyByStoreKeyLoginPost copy() {
132        return new ByProjectKeyInStoreKeyByStoreKeyLoginPost(this);
133    }
134}