/*
 * Jellyfin API
 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
 *
 * The version of the OpenAPI document: 10.11.6
 * 
 *
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */

package org.openhab.binding.jellyfin.internal.gen.current.model;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Objects;
import java.util.StringJoiner;

import com.fasterxml.jackson.annotation.JsonProperty;

/**
 * A class representing an authentication result.
 */
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "OpenAPI Generator")
public class AuthenticationResult {
    public static final String JSON_PROPERTY_USER = "User";
    private @org.eclipse.jdt.annotation.Nullable UserDto user;

    public static final String JSON_PROPERTY_SESSION_INFO = "SessionInfo";
    private @org.eclipse.jdt.annotation.Nullable SessionInfoDto sessionInfo;

    public static final String JSON_PROPERTY_ACCESS_TOKEN = "AccessToken";
    private @org.eclipse.jdt.annotation.Nullable String accessToken;

    public static final String JSON_PROPERTY_SERVER_ID = "ServerId";
    private @org.eclipse.jdt.annotation.Nullable String serverId;

    public AuthenticationResult() {
    }

    public AuthenticationResult user(@org.eclipse.jdt.annotation.Nullable UserDto user) {
        this.user = user;
        return this;
    }

    /**
     * Class UserDto.
     * 
     * @return user
     */
    @JsonProperty(value = JSON_PROPERTY_USER)
    public @org.eclipse.jdt.annotation.Nullable UserDto getUser() {
        return user;
    }

    @JsonProperty(value = JSON_PROPERTY_USER)
    public void setUser(@org.eclipse.jdt.annotation.Nullable UserDto user) {
        this.user = user;
    }

    public AuthenticationResult sessionInfo(@org.eclipse.jdt.annotation.Nullable SessionInfoDto sessionInfo) {
        this.sessionInfo = sessionInfo;
        return this;
    }

    /**
     * Session info DTO.
     * 
     * @return sessionInfo
     */
    @JsonProperty(value = JSON_PROPERTY_SESSION_INFO)
    public @org.eclipse.jdt.annotation.Nullable SessionInfoDto getSessionInfo() {
        return sessionInfo;
    }

    @JsonProperty(value = JSON_PROPERTY_SESSION_INFO)
    public void setSessionInfo(@org.eclipse.jdt.annotation.Nullable SessionInfoDto sessionInfo) {
        this.sessionInfo = sessionInfo;
    }

    public AuthenticationResult accessToken(@org.eclipse.jdt.annotation.Nullable String accessToken) {
        this.accessToken = accessToken;
        return this;
    }

    /**
     * Gets or sets the access token.
     * 
     * @return accessToken
     */
    @JsonProperty(value = JSON_PROPERTY_ACCESS_TOKEN)
    public @org.eclipse.jdt.annotation.Nullable String getAccessToken() {
        return accessToken;
    }

    @JsonProperty(value = JSON_PROPERTY_ACCESS_TOKEN)
    public void setAccessToken(@org.eclipse.jdt.annotation.Nullable String accessToken) {
        this.accessToken = accessToken;
    }

    public AuthenticationResult serverId(@org.eclipse.jdt.annotation.Nullable String serverId) {
        this.serverId = serverId;
        return this;
    }

    /**
     * Gets or sets the server id.
     * 
     * @return serverId
     */
    @JsonProperty(value = JSON_PROPERTY_SERVER_ID)
    public @org.eclipse.jdt.annotation.Nullable String getServerId() {
        return serverId;
    }

    @JsonProperty(value = JSON_PROPERTY_SERVER_ID)
    public void setServerId(@org.eclipse.jdt.annotation.Nullable String serverId) {
        this.serverId = serverId;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        AuthenticationResult authenticationResult = (AuthenticationResult) o;
        return Objects.equals(this.user, authenticationResult.user)
                && Objects.equals(this.sessionInfo, authenticationResult.sessionInfo)
                && Objects.equals(this.accessToken, authenticationResult.accessToken)
                && Objects.equals(this.serverId, authenticationResult.serverId);
    }

    @Override
    public int hashCode() {
        return Objects.hash(user, sessionInfo, accessToken, serverId);
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("class AuthenticationResult {\n");
        sb.append("    user: ").append(toIndentedString(user)).append("\n");
        sb.append("    sessionInfo: ").append(toIndentedString(sessionInfo)).append("\n");
        sb.append("    accessToken: ").append(toIndentedString(accessToken)).append("\n");
        sb.append("    serverId: ").append(toIndentedString(serverId)).append("\n");
        sb.append("}");
        return sb.toString();
    }

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

    /**
     * Convert the instance into URL query string.
     *
     * @return URL query string
     */
    public String toUrlQueryString() {
        return toUrlQueryString(null);
    }

    /**
     * Convert the instance into URL query string.
     *
     * @param prefix prefix of the query string
     * @return URL query string
     */
    public String toUrlQueryString(String prefix) {
        String suffix = "";
        String containerSuffix = "";
        String containerPrefix = "";
        if (prefix == null) {
            // style=form, explode=true, e.g. /pet?name=cat&type=manx
            prefix = "";
        } else {
            // deepObject style e.g. /pet?id[name]=cat&id[type]=manx
            prefix = prefix + "[";
            suffix = "]";
            containerSuffix = "]";
            containerPrefix = "[";
        }

        StringJoiner joiner = new StringJoiner("&");

        // add `User` to the URL query string
        if (getUser() != null) {
            joiner.add(getUser().toUrlQueryString(prefix + "User" + suffix));
        }

        // add `SessionInfo` to the URL query string
        if (getSessionInfo() != null) {
            joiner.add(getSessionInfo().toUrlQueryString(prefix + "SessionInfo" + suffix));
        }

        // add `AccessToken` to the URL query string
        if (getAccessToken() != null) {
            try {
                joiner.add(String.format(java.util.Locale.ROOT, "%sAccessToken%s=%s", prefix, suffix,
                        URLEncoder.encode(String.valueOf(getAccessToken()), "UTF-8").replaceAll("\\+", "%20")));
            } catch (UnsupportedEncodingException e) {
                // Should never happen, UTF-8 is always supported
                throw new RuntimeException(e);
            }
        }

        // add `ServerId` to the URL query string
        if (getServerId() != null) {
            try {
                joiner.add(String.format(java.util.Locale.ROOT, "%sServerId%s=%s", prefix, suffix,
                        URLEncoder.encode(String.valueOf(getServerId()), "UTF-8").replaceAll("\\+", "%20")));
            } catch (UnsupportedEncodingException e) {
                // Should never happen, UTF-8 is always supported
                throw new RuntimeException(e);
            }
        }

        return joiner.toString();
    }

    public static class Builder {

        private AuthenticationResult instance;

        public Builder() {
            this(new AuthenticationResult());
        }

        protected Builder(AuthenticationResult instance) {
            this.instance = instance;
        }

        public AuthenticationResult.Builder user(UserDto user) {
            this.instance.user = user;
            return this;
        }

        public AuthenticationResult.Builder sessionInfo(SessionInfoDto sessionInfo) {
            this.instance.sessionInfo = sessionInfo;
            return this;
        }

        public AuthenticationResult.Builder accessToken(String accessToken) {
            this.instance.accessToken = accessToken;
            return this;
        }

        public AuthenticationResult.Builder serverId(String serverId) {
            this.instance.serverId = serverId;
            return this;
        }

        /**
         * returns a built AuthenticationResult instance.
         *
         * The builder is not reusable.
         */
        public AuthenticationResult build() {
            try {
                return this.instance;
            } finally {
                // ensure that this.instance is not reused
                this.instance = null;
            }
        }

        @Override
        public String toString() {
            return getClass() + "=(" + instance + ")";
        }
    }

    /**
     * Create a builder with no initialized field.
     */
    public static AuthenticationResult.Builder builder() {
        return new AuthenticationResult.Builder();
    }

    /**
     * Create a builder with a shallow copy of this instance.
     */
    public AuthenticationResult.Builder toBuilder() {
        return new AuthenticationResult.Builder().user(getUser()).sessionInfo(getSessionInfo())
                .accessToken(getAccessToken()).serverId(getServerId());
    }
}
