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

/**
 * DTO for playlists.
 */
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "OpenAPI Generator")
public class PlaylistDto {
    public static final String JSON_PROPERTY_OPEN_ACCESS = "OpenAccess";
    private @org.eclipse.jdt.annotation.Nullable Boolean openAccess;

    public static final String JSON_PROPERTY_SHARES = "Shares";
    private @org.eclipse.jdt.annotation.Nullable List<PlaylistUserPermissions> shares = new ArrayList<>();

    public static final String JSON_PROPERTY_ITEM_IDS = "ItemIds";
    private @org.eclipse.jdt.annotation.Nullable List<UUID> itemIds = new ArrayList<>();

    public PlaylistDto() {
    }

    public PlaylistDto openAccess(@org.eclipse.jdt.annotation.Nullable Boolean openAccess) {
        this.openAccess = openAccess;
        return this;
    }

    /**
     * Gets or sets a value indicating whether the playlist is publicly readable.
     * 
     * @return openAccess
     */
    @JsonProperty(value = JSON_PROPERTY_OPEN_ACCESS)
    public @org.eclipse.jdt.annotation.Nullable Boolean getOpenAccess() {
        return openAccess;
    }

    @JsonProperty(value = JSON_PROPERTY_OPEN_ACCESS)
    public void setOpenAccess(@org.eclipse.jdt.annotation.Nullable Boolean openAccess) {
        this.openAccess = openAccess;
    }

    public PlaylistDto shares(@org.eclipse.jdt.annotation.Nullable List<PlaylistUserPermissions> shares) {
        this.shares = shares;
        return this;
    }

    public PlaylistDto addSharesItem(PlaylistUserPermissions sharesItem) {
        if (this.shares == null) {
            this.shares = new ArrayList<>();
        }
        this.shares.add(sharesItem);
        return this;
    }

    /**
     * Gets or sets the share permissions.
     * 
     * @return shares
     */
    @JsonProperty(value = JSON_PROPERTY_SHARES)
    public @org.eclipse.jdt.annotation.Nullable List<PlaylistUserPermissions> getShares() {
        return shares;
    }

    @JsonProperty(value = JSON_PROPERTY_SHARES)
    public void setShares(@org.eclipse.jdt.annotation.Nullable List<PlaylistUserPermissions> shares) {
        this.shares = shares;
    }

    public PlaylistDto itemIds(@org.eclipse.jdt.annotation.Nullable List<UUID> itemIds) {
        this.itemIds = itemIds;
        return this;
    }

    public PlaylistDto addItemIdsItem(UUID itemIdsItem) {
        if (this.itemIds == null) {
            this.itemIds = new ArrayList<>();
        }
        this.itemIds.add(itemIdsItem);
        return this;
    }

    /**
     * Gets or sets the item ids.
     * 
     * @return itemIds
     */
    @JsonProperty(value = JSON_PROPERTY_ITEM_IDS)
    public @org.eclipse.jdt.annotation.Nullable List<UUID> getItemIds() {
        return itemIds;
    }

    @JsonProperty(value = JSON_PROPERTY_ITEM_IDS)
    public void setItemIds(@org.eclipse.jdt.annotation.Nullable List<UUID> itemIds) {
        this.itemIds = itemIds;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        PlaylistDto playlistDto = (PlaylistDto) o;
        return Objects.equals(this.openAccess, playlistDto.openAccess)
                && Objects.equals(this.shares, playlistDto.shares) && Objects.equals(this.itemIds, playlistDto.itemIds);
    }

    @Override
    public int hashCode() {
        return Objects.hash(openAccess, shares, itemIds);
    }

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

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

        // add `ItemIds` to the URL query string
        if (getItemIds() != null) {
            for (int i = 0; i < getItemIds().size(); i++) {
                if (getItemIds().get(i) != null) {
                    try {
                        joiner.add(String.format(java.util.Locale.ROOT, "%sItemIds%s%s=%s", prefix, suffix,
                                "".equals(suffix) ? ""
                                        : String.format(java.util.Locale.ROOT, "%s%d%s", containerPrefix, i,
                                                containerSuffix),
                                URLEncoder.encode(String.valueOf(getItemIds().get(i)), "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 PlaylistDto instance;

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

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

        public PlaylistDto.Builder openAccess(Boolean openAccess) {
            this.instance.openAccess = openAccess;
            return this;
        }

        public PlaylistDto.Builder shares(List<PlaylistUserPermissions> shares) {
            this.instance.shares = shares;
            return this;
        }

        public PlaylistDto.Builder itemIds(List<UUID> itemIds) {
            this.instance.itemIds = itemIds;
            return this;
        }

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

    /**
     * Create a builder with a shallow copy of this instance.
     */
    public PlaylistDto.Builder toBuilder() {
        return new PlaylistDto.Builder().openAccess(getOpenAccess()).shares(getShares()).itemIds(getItemIds());
    }
}
