/*
 * 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.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.StringJoiner;
import java.util.UUID;

import com.fasterxml.jackson.annotation.JsonProperty;

/**
 * Class PackageInfo.
 */
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "OpenAPI Generator")
public class PackageInfo {
    public static final String JSON_PROPERTY_NAME = "name";
    private @org.eclipse.jdt.annotation.Nullable String name;

    public static final String JSON_PROPERTY_DESCRIPTION = "description";
    private @org.eclipse.jdt.annotation.Nullable String description;

    public static final String JSON_PROPERTY_OVERVIEW = "overview";
    private @org.eclipse.jdt.annotation.Nullable String overview;

    public static final String JSON_PROPERTY_OWNER = "owner";
    private @org.eclipse.jdt.annotation.Nullable String owner;

    public static final String JSON_PROPERTY_CATEGORY = "category";
    private @org.eclipse.jdt.annotation.Nullable String category;

    public static final String JSON_PROPERTY_GUID = "guid";
    private @org.eclipse.jdt.annotation.Nullable UUID guid;

    public static final String JSON_PROPERTY_VERSIONS = "versions";
    private @org.eclipse.jdt.annotation.Nullable List<VersionInfo> versions = new ArrayList<>();

    public static final String JSON_PROPERTY_IMAGE_URL = "imageUrl";
    private @org.eclipse.jdt.annotation.Nullable String imageUrl;

    public PackageInfo() {
    }

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

    /**
     * Gets or sets 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 PackageInfo description(@org.eclipse.jdt.annotation.Nullable String description) {
        this.description = description;
        return this;
    }

    /**
     * Gets or sets a long description of the plugin containing features or helpful explanations.
     * 
     * @return description
     */
    @JsonProperty(value = JSON_PROPERTY_DESCRIPTION)
    public @org.eclipse.jdt.annotation.Nullable String getDescription() {
        return description;
    }

    @JsonProperty(value = JSON_PROPERTY_DESCRIPTION)
    public void setDescription(@org.eclipse.jdt.annotation.Nullable String description) {
        this.description = description;
    }

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

    /**
     * Gets or sets a short overview of what the plugin does.
     * 
     * @return overview
     */
    @JsonProperty(value = JSON_PROPERTY_OVERVIEW)
    public @org.eclipse.jdt.annotation.Nullable String getOverview() {
        return overview;
    }

    @JsonProperty(value = JSON_PROPERTY_OVERVIEW)
    public void setOverview(@org.eclipse.jdt.annotation.Nullable String overview) {
        this.overview = overview;
    }

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

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

    @JsonProperty(value = JSON_PROPERTY_OWNER)
    public void setOwner(@org.eclipse.jdt.annotation.Nullable String owner) {
        this.owner = owner;
    }

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

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

    @JsonProperty(value = JSON_PROPERTY_CATEGORY)
    public void setCategory(@org.eclipse.jdt.annotation.Nullable String category) {
        this.category = category;
    }

    public PackageInfo guid(@org.eclipse.jdt.annotation.Nullable UUID guid) {
        this.guid = guid;
        return this;
    }

    /**
     * Gets or sets the guid of the assembly associated with this plugin. This is used to identify the proper item for
     * automatic updates.
     * 
     * @return guid
     */
    @JsonProperty(value = JSON_PROPERTY_GUID)
    public @org.eclipse.jdt.annotation.Nullable UUID getGuid() {
        return guid;
    }

    @JsonProperty(value = JSON_PROPERTY_GUID)
    public void setGuid(@org.eclipse.jdt.annotation.Nullable UUID guid) {
        this.guid = guid;
    }

    public PackageInfo versions(@org.eclipse.jdt.annotation.Nullable List<VersionInfo> versions) {
        this.versions = versions;
        return this;
    }

    public PackageInfo addVersionsItem(VersionInfo versionsItem) {
        if (this.versions == null) {
            this.versions = new ArrayList<>();
        }
        this.versions.add(versionsItem);
        return this;
    }

    /**
     * Gets or sets the versions.
     * 
     * @return versions
     */
    @JsonProperty(value = JSON_PROPERTY_VERSIONS)
    public @org.eclipse.jdt.annotation.Nullable List<VersionInfo> getVersions() {
        return versions;
    }

    @JsonProperty(value = JSON_PROPERTY_VERSIONS)
    public void setVersions(@org.eclipse.jdt.annotation.Nullable List<VersionInfo> versions) {
        this.versions = versions;
    }

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

    /**
     * Gets or sets the image url for the package.
     * 
     * @return imageUrl
     */
    @JsonProperty(value = JSON_PROPERTY_IMAGE_URL)
    public @org.eclipse.jdt.annotation.Nullable String getImageUrl() {
        return imageUrl;
    }

    @JsonProperty(value = JSON_PROPERTY_IMAGE_URL)
    public void setImageUrl(@org.eclipse.jdt.annotation.Nullable String imageUrl) {
        this.imageUrl = imageUrl;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        PackageInfo packageInfo = (PackageInfo) o;
        return Objects.equals(this.name, packageInfo.name) && Objects.equals(this.description, packageInfo.description)
                && Objects.equals(this.overview, packageInfo.overview) && Objects.equals(this.owner, packageInfo.owner)
                && Objects.equals(this.category, packageInfo.category) && Objects.equals(this.guid, packageInfo.guid)
                && Objects.equals(this.versions, packageInfo.versions)
                && Objects.equals(this.imageUrl, packageInfo.imageUrl);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, description, overview, owner, category, guid, versions, imageUrl);
    }

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

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

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

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

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

        // add `versions` to the URL query string
        if (getVersions() != null) {
            for (int i = 0; i < getVersions().size(); i++) {
                if (getVersions().get(i) != null) {
                    joiner.add(getVersions().get(i)
                            .toUrlQueryString(String.format(java.util.Locale.ROOT, "%sversions%s%s", prefix, suffix,
                                    "".equals(suffix) ? ""
                                            : String.format(java.util.Locale.ROOT, "%s%d%s", containerPrefix, i,
                                                    containerSuffix))));
                }
            }
        }

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

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

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

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

        public PackageInfo.Builder description(String description) {
            this.instance.description = description;
            return this;
        }

        public PackageInfo.Builder overview(String overview) {
            this.instance.overview = overview;
            return this;
        }

        public PackageInfo.Builder owner(String owner) {
            this.instance.owner = owner;
            return this;
        }

        public PackageInfo.Builder category(String category) {
            this.instance.category = category;
            return this;
        }

        public PackageInfo.Builder guid(UUID guid) {
            this.instance.guid = guid;
            return this;
        }

        public PackageInfo.Builder versions(List<VersionInfo> versions) {
            this.instance.versions = versions;
            return this;
        }

        public PackageInfo.Builder imageUrl(String imageUrl) {
            this.instance.imageUrl = imageUrl;
            return this;
        }

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

    /**
     * Create a builder with a shallow copy of this instance.
     */
    public PackageInfo.Builder toBuilder() {
        return new PackageInfo.Builder().name(getName()).description(getDescription()).overview(getOverview())
                .owner(getOwner()).category(getCategory()).guid(getGuid()).versions(getVersions())
                .imageUrl(getImageUrl());
    }
}
