/*
 * 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 server discovery info model.
 */
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "OpenAPI Generator")
public class ServerDiscoveryInfo {
    public static final String JSON_PROPERTY_ADDRESS = "Address";
    private @org.eclipse.jdt.annotation.Nullable String address;

    public static final String JSON_PROPERTY_ID = "Id";
    private @org.eclipse.jdt.annotation.Nullable String id;

    public static final String JSON_PROPERTY_NAME = "Name";
    private @org.eclipse.jdt.annotation.Nullable String name;

    public static final String JSON_PROPERTY_ENDPOINT_ADDRESS = "EndpointAddress";
    private @org.eclipse.jdt.annotation.Nullable String endpointAddress;

    public ServerDiscoveryInfo() {
    }

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

    /**
     * Gets the address.
     * 
     * @return address
     */
    @JsonProperty(value = JSON_PROPERTY_ADDRESS)
    public @org.eclipse.jdt.annotation.Nullable String getAddress() {
        return address;
    }

    @JsonProperty(value = JSON_PROPERTY_ADDRESS)
    public void setAddress(@org.eclipse.jdt.annotation.Nullable String address) {
        this.address = address;
    }

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

    /**
     * Gets the server identifier.
     * 
     * @return id
     */
    @JsonProperty(value = JSON_PROPERTY_ID)
    public @org.eclipse.jdt.annotation.Nullable String getId() {
        return id;
    }

    @JsonProperty(value = JSON_PROPERTY_ID)
    public void setId(@org.eclipse.jdt.annotation.Nullable String id) {
        this.id = id;
    }

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

    /**
     * Gets the name.
     * 
     * @return name
     */
    @JsonProperty(value = JSON_PROPERTY_NAME)
    public @org.eclipse.jdt.annotation.Nullable String getName() {
        return name;
    }

    @JsonProperty(value = JSON_PROPERTY_NAME)
    public void setName(@org.eclipse.jdt.annotation.Nullable String name) {
        this.name = name;
    }

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

    /**
     * Gets the endpoint address.
     * 
     * @return endpointAddress
     */
    @JsonProperty(value = JSON_PROPERTY_ENDPOINT_ADDRESS)
    public @org.eclipse.jdt.annotation.Nullable String getEndpointAddress() {
        return endpointAddress;
    }

    @JsonProperty(value = JSON_PROPERTY_ENDPOINT_ADDRESS)
    public void setEndpointAddress(@org.eclipse.jdt.annotation.Nullable String endpointAddress) {
        this.endpointAddress = endpointAddress;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        ServerDiscoveryInfo serverDiscoveryInfo = (ServerDiscoveryInfo) o;
        return Objects.equals(this.address, serverDiscoveryInfo.address)
                && Objects.equals(this.id, serverDiscoveryInfo.id)
                && Objects.equals(this.name, serverDiscoveryInfo.name)
                && Objects.equals(this.endpointAddress, serverDiscoveryInfo.endpointAddress);
    }

    @Override
    public int hashCode() {
        return Objects.hash(address, id, name, endpointAddress);
    }

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

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

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

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

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

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

        public ServerDiscoveryInfo.Builder address(String address) {
            this.instance.address = address;
            return this;
        }

        public ServerDiscoveryInfo.Builder id(String id) {
            this.instance.id = id;
            return this;
        }

        public ServerDiscoveryInfo.Builder name(String name) {
            this.instance.name = name;
            return this;
        }

        public ServerDiscoveryInfo.Builder endpointAddress(String endpointAddress) {
            this.instance.endpointAddress = endpointAddress;
            return this;
        }

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

    /**
     * Create a builder with a shallow copy of this instance.
     */
    public ServerDiscoveryInfo.Builder toBuilder() {
        return new ServerDiscoveryInfo.Builder().address(getAddress()).id(getId()).name(getName())
                .endpointAddress(getEndpointAddress());
    }
}
