/*
 * 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;

/**
 * The authenticate user by name request body.
 */
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "OpenAPI Generator")
public class AuthenticateUserByName {
    public static final String JSON_PROPERTY_USERNAME = "Username";
    private @org.eclipse.jdt.annotation.Nullable String username;

    public static final String JSON_PROPERTY_PW = "Pw";
    private @org.eclipse.jdt.annotation.Nullable String pw;

    public AuthenticateUserByName() {
    }

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

    /**
     * Gets or sets the username.
     * 
     * @return username
     */
    @JsonProperty(value = JSON_PROPERTY_USERNAME)
    public @org.eclipse.jdt.annotation.Nullable String getUsername() {
        return username;
    }

    @JsonProperty(value = JSON_PROPERTY_USERNAME)
    public void setUsername(@org.eclipse.jdt.annotation.Nullable String username) {
        this.username = username;
    }

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

    /**
     * Gets or sets the plain text password.
     * 
     * @return pw
     */
    @JsonProperty(value = JSON_PROPERTY_PW)
    public @org.eclipse.jdt.annotation.Nullable String getPw() {
        return pw;
    }

    @JsonProperty(value = JSON_PROPERTY_PW)
    public void setPw(@org.eclipse.jdt.annotation.Nullable String pw) {
        this.pw = pw;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        AuthenticateUserByName authenticateUserByName = (AuthenticateUserByName) o;
        return Objects.equals(this.username, authenticateUserByName.username)
                && Objects.equals(this.pw, authenticateUserByName.pw);
    }

    @Override
    public int hashCode() {
        return Objects.hash(username, pw);
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("class AuthenticateUserByName {\n");
        sb.append("    username: ").append(toIndentedString(username)).append("\n");
        sb.append("    pw: ").append(toIndentedString(pw)).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 `Username` to the URL query string
        if (getUsername() != null) {
            try {
                joiner.add(String.format(java.util.Locale.ROOT, "%sUsername%s=%s", prefix, suffix,
                        URLEncoder.encode(String.valueOf(getUsername()), "UTF-8").replaceAll("\\+", "%20")));
            } catch (UnsupportedEncodingException e) {
                // Should never happen, UTF-8 is always supported
                throw new RuntimeException(e);
            }
        }

        // add `Pw` to the URL query string
        if (getPw() != null) {
            try {
                joiner.add(String.format(java.util.Locale.ROOT, "%sPw%s=%s", prefix, suffix,
                        URLEncoder.encode(String.valueOf(getPw()), "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 AuthenticateUserByName instance;

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

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

        public AuthenticateUserByName.Builder username(String username) {
            this.instance.username = username;
            return this;
        }

        public AuthenticateUserByName.Builder pw(String pw) {
            this.instance.pw = pw;
            return this;
        }

        /**
         * returns a built AuthenticateUserByName instance.
         *
         * The builder is not reusable.
         */
        public AuthenticateUserByName 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 AuthenticateUserByName.Builder builder() {
        return new AuthenticateUserByName.Builder();
    }

    /**
     * Create a builder with a shallow copy of this instance.
     */
    public AuthenticateUserByName.Builder toBuilder() {
        return new AuthenticateUserByName.Builder().username(getUsername()).pw(getPw());
    }
}
