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

/**
 * Represents the external id information for serialization to the client.
 */
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "OpenAPI Generator")
public class ExternalIdInfo {
    public static final String JSON_PROPERTY_NAME = "Name";
    private @org.eclipse.jdt.annotation.Nullable String name;

    public static final String JSON_PROPERTY_KEY = "Key";
    private @org.eclipse.jdt.annotation.Nullable String key;

    public static final String JSON_PROPERTY_TYPE = "Type";
    private @org.eclipse.jdt.annotation.Nullable ExternalIdMediaType type;

    public ExternalIdInfo() {
    }

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

    /**
     * Gets or sets the display name of the external id provider (IE: IMDB, MusicBrainz, etc).
     * 
     * @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 ExternalIdInfo key(@org.eclipse.jdt.annotation.Nullable String key) {
        this.key = key;
        return this;
    }

    /**
     * Gets or sets the unique key for this id. This key should be unique across all providers.
     * 
     * @return key
     */
    @JsonProperty(value = JSON_PROPERTY_KEY)
    public @org.eclipse.jdt.annotation.Nullable String getKey() {
        return key;
    }

    @JsonProperty(value = JSON_PROPERTY_KEY)
    public void setKey(@org.eclipse.jdt.annotation.Nullable String key) {
        this.key = key;
    }

    public ExternalIdInfo type(@org.eclipse.jdt.annotation.Nullable ExternalIdMediaType type) {
        this.type = type;
        return this;
    }

    /**
     * Gets or sets the specific media type for this id. This is used to distinguish between the different external id
     * types for providers with multiple ids. A null value indicates there is no specific media type associated with the
     * external id, or this is the default id for the external provider so there is no need to specify a type.
     * 
     * @return type
     */
    @JsonProperty(value = JSON_PROPERTY_TYPE)
    public @org.eclipse.jdt.annotation.Nullable ExternalIdMediaType getType() {
        return type;
    }

    @JsonProperty(value = JSON_PROPERTY_TYPE)
    public void setType(@org.eclipse.jdt.annotation.Nullable ExternalIdMediaType type) {
        this.type = type;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        ExternalIdInfo externalIdInfo = (ExternalIdInfo) o;
        return Objects.equals(this.name, externalIdInfo.name) && Objects.equals(this.key, externalIdInfo.key)
                && Objects.equals(this.type, externalIdInfo.type);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, key, type);
    }

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

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

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

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

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

        public ExternalIdInfo.Builder key(String key) {
            this.instance.key = key;
            return this;
        }

        public ExternalIdInfo.Builder type(ExternalIdMediaType type) {
            this.instance.type = type;
            return this;
        }

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

    /**
     * Create a builder with a shallow copy of this instance.
     */
    public ExternalIdInfo.Builder toBuilder() {
        return new ExternalIdInfo.Builder().name(getName()).key(getKey()).type(getType());
    }
}
