package io.delphiplatform.api.v2.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

import org.springframework.validation.annotation.Validated;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

import lombok.Builder;

/**
 * AuthTokenRequestBody
 */
@Builder
@Validated
@JsonInclude(JsonInclude.Include.NON_NULL)
public class AuthTokenRequestBody {

    @JsonProperty("audience")
    private String audience;
    @JsonProperty("client_id")
    private String clientId = null;
    @JsonProperty("client_secret")
    private String clientSecret = null;
    @JsonProperty("grant_type")
    private String grantType;

    public String getAudience() {
        return audience;
    }

    public void setAudience(String audience) {
        this.audience = audience;
    }

    @JsonIgnore
    public Map<String, String> getMap() {
        Map<String, String> map = new HashMap<>();
        map.compute("client_id", (k, v) -> this.getClientId());
        map.compute("client_secret", (k, v) -> this.getClientSecret());
        map.compute("audience", (k, v) -> this.getAudience());
        map.compute("grant_type", (k, v) -> this.getGrantType());
        return map;
    }

    public AuthTokenRequestBody clientId(String clientId) {
        this.clientId = clientId;
        return this;
    }

    /**
     * Required – `client_id` from identity provider credentials
     *
     * @return clientId
     **/
    public String getClientId() {
        return clientId;
    }

    public void setClientId(String clientId) {
        this.clientId = clientId;
    }

    public AuthTokenRequestBody clientSecret(String clientSecret) {
        this.clientSecret = clientSecret;
        return this;
    }

    /**
     * Required – `client_secret` from identity provider credentials
     *
     * @return clientSecret
     **/
    public String getClientSecret() {
        return clientSecret;
    }

    public void setClientSecret(String clientSecret) {
        this.clientSecret = clientSecret;
    }

    public AuthTokenRequestBody grantType(String grantType) {
        this.grantType = grantType;
        return this;
    }

    /**
     * (optional) Defaults to `client_credentials` as the only currently supported method
     *
     * @return grantType
     **/
    public String getGrantType() {
        return grantType;
    }

    public void setGrantType(String grantType) {
        this.grantType = grantType;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        AuthTokenRequestBody authTokenRequestBody = (AuthTokenRequestBody) o;
        return Objects.equals(this.clientId, authTokenRequestBody.clientId) &&
            Objects.equals(this.clientSecret, authTokenRequestBody.clientSecret) &&
            Objects.equals(this.grantType, authTokenRequestBody.grantType);
    }

    @Override
    public int hashCode() {
        return Objects.hash(clientId, clientSecret, grantType);
    }

    @Override
    public String toString() {

        return "class AuthTokenRequestBody {\n" +
            "    clientId: " + toIndentedString(clientId) + "\n" +
            "    clientSecret: " + toIndentedString(clientSecret) + "\n" +
            "    grantType: " + toIndentedString(grantType) + "\n" +
            "    audience: " + toIndentedString(audience) + "\n" +
            "}";
    }

    /**
     * Convert the given object to string with each line indented by 4 spaces (except the first line).
     */
    private String toIndentedString(Object o) {
        if (o == null) {
            return "null";
        }
        return o.toString().replace("\n", "\n    ");
    }
}
