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

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

    public static final String JSON_PROPERTY_IDS = "Ids";
    private @org.eclipse.jdt.annotation.Nullable List<UUID> ids = new ArrayList<>();

    public static final String JSON_PROPERTY_USER_ID = "UserId";
    private @org.eclipse.jdt.annotation.Nullable UUID userId;

    public static final String JSON_PROPERTY_MEDIA_TYPE = "MediaType";
    private @org.eclipse.jdt.annotation.Nullable MediaType mediaType;

    public static final String JSON_PROPERTY_USERS = "Users";
    private @org.eclipse.jdt.annotation.Nullable List<PlaylistUserPermissions> users = new ArrayList<>();

    public static final String JSON_PROPERTY_IS_PUBLIC = "IsPublic";
    private @org.eclipse.jdt.annotation.Nullable Boolean isPublic;

    public CreatePlaylistDto() {
    }

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

    /**
     * Gets or sets the name of the new playlist.
     * 
     * @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 CreatePlaylistDto ids(@org.eclipse.jdt.annotation.Nullable List<UUID> ids) {
        this.ids = ids;
        return this;
    }

    public CreatePlaylistDto addIdsItem(UUID idsItem) {
        if (this.ids == null) {
            this.ids = new ArrayList<>();
        }
        this.ids.add(idsItem);
        return this;
    }

    /**
     * Gets or sets item ids to add to the playlist.
     * 
     * @return ids
     */
    @JsonProperty(value = JSON_PROPERTY_IDS)
    public @org.eclipse.jdt.annotation.Nullable List<UUID> getIds() {
        return ids;
    }

    @JsonProperty(value = JSON_PROPERTY_IDS)
    public void setIds(@org.eclipse.jdt.annotation.Nullable List<UUID> ids) {
        this.ids = ids;
    }

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

    /**
     * Gets or sets the user id.
     * 
     * @return userId
     */
    @JsonProperty(value = JSON_PROPERTY_USER_ID)
    public @org.eclipse.jdt.annotation.Nullable UUID getUserId() {
        return userId;
    }

    @JsonProperty(value = JSON_PROPERTY_USER_ID)
    public void setUserId(@org.eclipse.jdt.annotation.Nullable UUID userId) {
        this.userId = userId;
    }

    public CreatePlaylistDto mediaType(@org.eclipse.jdt.annotation.Nullable MediaType mediaType) {
        this.mediaType = mediaType;
        return this;
    }

    /**
     * Gets or sets the media type.
     * 
     * @return mediaType
     */
    @JsonProperty(value = JSON_PROPERTY_MEDIA_TYPE)
    public @org.eclipse.jdt.annotation.Nullable MediaType getMediaType() {
        return mediaType;
    }

    @JsonProperty(value = JSON_PROPERTY_MEDIA_TYPE)
    public void setMediaType(@org.eclipse.jdt.annotation.Nullable MediaType mediaType) {
        this.mediaType = mediaType;
    }

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

    public CreatePlaylistDto addUsersItem(PlaylistUserPermissions usersItem) {
        if (this.users == null) {
            this.users = new ArrayList<>();
        }
        this.users.add(usersItem);
        return this;
    }

    /**
     * Gets or sets the playlist users.
     * 
     * @return users
     */
    @JsonProperty(value = JSON_PROPERTY_USERS)
    public @org.eclipse.jdt.annotation.Nullable List<PlaylistUserPermissions> getUsers() {
        return users;
    }

    @JsonProperty(value = JSON_PROPERTY_USERS)
    public void setUsers(@org.eclipse.jdt.annotation.Nullable List<PlaylistUserPermissions> users) {
        this.users = users;
    }

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

    /**
     * Gets or sets a value indicating whether the playlist is public.
     * 
     * @return isPublic
     */
    @JsonProperty(value = JSON_PROPERTY_IS_PUBLIC)
    public @org.eclipse.jdt.annotation.Nullable Boolean getIsPublic() {
        return isPublic;
    }

    @JsonProperty(value = JSON_PROPERTY_IS_PUBLIC)
    public void setIsPublic(@org.eclipse.jdt.annotation.Nullable Boolean isPublic) {
        this.isPublic = isPublic;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        CreatePlaylistDto createPlaylistDto = (CreatePlaylistDto) o;
        return Objects.equals(this.name, createPlaylistDto.name) && Objects.equals(this.ids, createPlaylistDto.ids)
                && Objects.equals(this.userId, createPlaylistDto.userId)
                && Objects.equals(this.mediaType, createPlaylistDto.mediaType)
                && Objects.equals(this.users, createPlaylistDto.users)
                && Objects.equals(this.isPublic, createPlaylistDto.isPublic);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, ids, userId, mediaType, users, isPublic);
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("class CreatePlaylistDto {\n");
        sb.append("    name: ").append(toIndentedString(name)).append("\n");
        sb.append("    ids: ").append(toIndentedString(ids)).append("\n");
        sb.append("    userId: ").append(toIndentedString(userId)).append("\n");
        sb.append("    mediaType: ").append(toIndentedString(mediaType)).append("\n");
        sb.append("    users: ").append(toIndentedString(users)).append("\n");
        sb.append("    isPublic: ").append(toIndentedString(isPublic)).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 `Ids` to the URL query string
        if (getIds() != null) {
            for (int i = 0; i < getIds().size(); i++) {
                if (getIds().get(i) != null) {
                    try {
                        joiner.add(String.format(java.util.Locale.ROOT, "%sIds%s%s=%s", prefix, suffix,
                                "".equals(suffix) ? ""
                                        : String.format(java.util.Locale.ROOT, "%s%d%s", containerPrefix, i,
                                                containerSuffix),
                                URLEncoder.encode(String.valueOf(getIds().get(i)), "UTF-8").replaceAll("\\+", "%20")));
                    } catch (UnsupportedEncodingException e) {
                        // Should never happen, UTF-8 is always supported
                        throw new RuntimeException(e);
                    }
                }
            }
        }

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

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

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

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

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

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

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

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

        public CreatePlaylistDto.Builder userId(UUID userId) {
            this.instance.userId = userId;
            return this;
        }

        public CreatePlaylistDto.Builder mediaType(MediaType mediaType) {
            this.instance.mediaType = mediaType;
            return this;
        }

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

        public CreatePlaylistDto.Builder isPublic(Boolean isPublic) {
            this.instance.isPublic = isPublic;
            return this;
        }

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

    /**
     * Create a builder with a shallow copy of this instance.
     */
    public CreatePlaylistDto.Builder toBuilder() {
        return new CreatePlaylistDto.Builder().name(getName()).ids(getIds()).userId(getUserId())
                .mediaType(getMediaType()).users(getUsers()).isPublic(getIsPublic());
    }
}
