/*
 * 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 UserConfiguration.
 */
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "OpenAPI Generator")
public class UserConfiguration {
    public static final String JSON_PROPERTY_AUDIO_LANGUAGE_PREFERENCE = "AudioLanguagePreference";
    private @org.eclipse.jdt.annotation.Nullable String audioLanguagePreference;

    public static final String JSON_PROPERTY_PLAY_DEFAULT_AUDIO_TRACK = "PlayDefaultAudioTrack";
    private @org.eclipse.jdt.annotation.Nullable Boolean playDefaultAudioTrack;

    public static final String JSON_PROPERTY_SUBTITLE_LANGUAGE_PREFERENCE = "SubtitleLanguagePreference";
    private @org.eclipse.jdt.annotation.Nullable String subtitleLanguagePreference;

    public static final String JSON_PROPERTY_DISPLAY_MISSING_EPISODES = "DisplayMissingEpisodes";
    private @org.eclipse.jdt.annotation.Nullable Boolean displayMissingEpisodes;

    public static final String JSON_PROPERTY_GROUPED_FOLDERS = "GroupedFolders";
    private @org.eclipse.jdt.annotation.Nullable List<UUID> groupedFolders = new ArrayList<>();

    public static final String JSON_PROPERTY_SUBTITLE_MODE = "SubtitleMode";
    private @org.eclipse.jdt.annotation.Nullable SubtitlePlaybackMode subtitleMode;

    public static final String JSON_PROPERTY_DISPLAY_COLLECTIONS_VIEW = "DisplayCollectionsView";
    private @org.eclipse.jdt.annotation.Nullable Boolean displayCollectionsView;

    public static final String JSON_PROPERTY_ENABLE_LOCAL_PASSWORD = "EnableLocalPassword";
    private @org.eclipse.jdt.annotation.Nullable Boolean enableLocalPassword;

    public static final String JSON_PROPERTY_ORDERED_VIEWS = "OrderedViews";
    private @org.eclipse.jdt.annotation.Nullable List<UUID> orderedViews = new ArrayList<>();

    public static final String JSON_PROPERTY_LATEST_ITEMS_EXCLUDES = "LatestItemsExcludes";
    private @org.eclipse.jdt.annotation.Nullable List<UUID> latestItemsExcludes = new ArrayList<>();

    public static final String JSON_PROPERTY_MY_MEDIA_EXCLUDES = "MyMediaExcludes";
    private @org.eclipse.jdt.annotation.Nullable List<UUID> myMediaExcludes = new ArrayList<>();

    public static final String JSON_PROPERTY_HIDE_PLAYED_IN_LATEST = "HidePlayedInLatest";
    private @org.eclipse.jdt.annotation.Nullable Boolean hidePlayedInLatest;

    public static final String JSON_PROPERTY_REMEMBER_AUDIO_SELECTIONS = "RememberAudioSelections";
    private @org.eclipse.jdt.annotation.Nullable Boolean rememberAudioSelections;

    public static final String JSON_PROPERTY_REMEMBER_SUBTITLE_SELECTIONS = "RememberSubtitleSelections";
    private @org.eclipse.jdt.annotation.Nullable Boolean rememberSubtitleSelections;

    public static final String JSON_PROPERTY_ENABLE_NEXT_EPISODE_AUTO_PLAY = "EnableNextEpisodeAutoPlay";
    private @org.eclipse.jdt.annotation.Nullable Boolean enableNextEpisodeAutoPlay;

    public static final String JSON_PROPERTY_CAST_RECEIVER_ID = "CastReceiverId";
    private @org.eclipse.jdt.annotation.Nullable String castReceiverId;

    public UserConfiguration() {
    }

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

    /**
     * Gets or sets the audio language preference.
     * 
     * @return audioLanguagePreference
     */
    @JsonProperty(value = JSON_PROPERTY_AUDIO_LANGUAGE_PREFERENCE)
    public @org.eclipse.jdt.annotation.Nullable String getAudioLanguagePreference() {
        return audioLanguagePreference;
    }

    @JsonProperty(value = JSON_PROPERTY_AUDIO_LANGUAGE_PREFERENCE)
    public void setAudioLanguagePreference(@org.eclipse.jdt.annotation.Nullable String audioLanguagePreference) {
        this.audioLanguagePreference = audioLanguagePreference;
    }

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

    /**
     * Gets or sets a value indicating whether [play default audio track].
     * 
     * @return playDefaultAudioTrack
     */
    @JsonProperty(value = JSON_PROPERTY_PLAY_DEFAULT_AUDIO_TRACK)
    public @org.eclipse.jdt.annotation.Nullable Boolean getPlayDefaultAudioTrack() {
        return playDefaultAudioTrack;
    }

    @JsonProperty(value = JSON_PROPERTY_PLAY_DEFAULT_AUDIO_TRACK)
    public void setPlayDefaultAudioTrack(@org.eclipse.jdt.annotation.Nullable Boolean playDefaultAudioTrack) {
        this.playDefaultAudioTrack = playDefaultAudioTrack;
    }

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

    /**
     * Gets or sets the subtitle language preference.
     * 
     * @return subtitleLanguagePreference
     */
    @JsonProperty(value = JSON_PROPERTY_SUBTITLE_LANGUAGE_PREFERENCE)
    public @org.eclipse.jdt.annotation.Nullable String getSubtitleLanguagePreference() {
        return subtitleLanguagePreference;
    }

    @JsonProperty(value = JSON_PROPERTY_SUBTITLE_LANGUAGE_PREFERENCE)
    public void setSubtitleLanguagePreference(@org.eclipse.jdt.annotation.Nullable String subtitleLanguagePreference) {
        this.subtitleLanguagePreference = subtitleLanguagePreference;
    }

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

    /**
     * Get displayMissingEpisodes
     * 
     * @return displayMissingEpisodes
     */
    @JsonProperty(value = JSON_PROPERTY_DISPLAY_MISSING_EPISODES)
    public @org.eclipse.jdt.annotation.Nullable Boolean getDisplayMissingEpisodes() {
        return displayMissingEpisodes;
    }

    @JsonProperty(value = JSON_PROPERTY_DISPLAY_MISSING_EPISODES)
    public void setDisplayMissingEpisodes(@org.eclipse.jdt.annotation.Nullable Boolean displayMissingEpisodes) {
        this.displayMissingEpisodes = displayMissingEpisodes;
    }

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

    public UserConfiguration addGroupedFoldersItem(UUID groupedFoldersItem) {
        if (this.groupedFolders == null) {
            this.groupedFolders = new ArrayList<>();
        }
        this.groupedFolders.add(groupedFoldersItem);
        return this;
    }

    /**
     * Get groupedFolders
     * 
     * @return groupedFolders
     */
    @JsonProperty(value = JSON_PROPERTY_GROUPED_FOLDERS)
    public @org.eclipse.jdt.annotation.Nullable List<UUID> getGroupedFolders() {
        return groupedFolders;
    }

    @JsonProperty(value = JSON_PROPERTY_GROUPED_FOLDERS)
    public void setGroupedFolders(@org.eclipse.jdt.annotation.Nullable List<UUID> groupedFolders) {
        this.groupedFolders = groupedFolders;
    }

    public UserConfiguration subtitleMode(@org.eclipse.jdt.annotation.Nullable SubtitlePlaybackMode subtitleMode) {
        this.subtitleMode = subtitleMode;
        return this;
    }

    /**
     * An enum representing a subtitle playback mode.
     * 
     * @return subtitleMode
     */
    @JsonProperty(value = JSON_PROPERTY_SUBTITLE_MODE)
    public @org.eclipse.jdt.annotation.Nullable SubtitlePlaybackMode getSubtitleMode() {
        return subtitleMode;
    }

    @JsonProperty(value = JSON_PROPERTY_SUBTITLE_MODE)
    public void setSubtitleMode(@org.eclipse.jdt.annotation.Nullable SubtitlePlaybackMode subtitleMode) {
        this.subtitleMode = subtitleMode;
    }

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

    /**
     * Get displayCollectionsView
     * 
     * @return displayCollectionsView
     */
    @JsonProperty(value = JSON_PROPERTY_DISPLAY_COLLECTIONS_VIEW)
    public @org.eclipse.jdt.annotation.Nullable Boolean getDisplayCollectionsView() {
        return displayCollectionsView;
    }

    @JsonProperty(value = JSON_PROPERTY_DISPLAY_COLLECTIONS_VIEW)
    public void setDisplayCollectionsView(@org.eclipse.jdt.annotation.Nullable Boolean displayCollectionsView) {
        this.displayCollectionsView = displayCollectionsView;
    }

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

    /**
     * Get enableLocalPassword
     * 
     * @return enableLocalPassword
     */
    @JsonProperty(value = JSON_PROPERTY_ENABLE_LOCAL_PASSWORD)
    public @org.eclipse.jdt.annotation.Nullable Boolean getEnableLocalPassword() {
        return enableLocalPassword;
    }

    @JsonProperty(value = JSON_PROPERTY_ENABLE_LOCAL_PASSWORD)
    public void setEnableLocalPassword(@org.eclipse.jdt.annotation.Nullable Boolean enableLocalPassword) {
        this.enableLocalPassword = enableLocalPassword;
    }

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

    public UserConfiguration addOrderedViewsItem(UUID orderedViewsItem) {
        if (this.orderedViews == null) {
            this.orderedViews = new ArrayList<>();
        }
        this.orderedViews.add(orderedViewsItem);
        return this;
    }

    /**
     * Get orderedViews
     * 
     * @return orderedViews
     */
    @JsonProperty(value = JSON_PROPERTY_ORDERED_VIEWS)
    public @org.eclipse.jdt.annotation.Nullable List<UUID> getOrderedViews() {
        return orderedViews;
    }

    @JsonProperty(value = JSON_PROPERTY_ORDERED_VIEWS)
    public void setOrderedViews(@org.eclipse.jdt.annotation.Nullable List<UUID> orderedViews) {
        this.orderedViews = orderedViews;
    }

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

    public UserConfiguration addLatestItemsExcludesItem(UUID latestItemsExcludesItem) {
        if (this.latestItemsExcludes == null) {
            this.latestItemsExcludes = new ArrayList<>();
        }
        this.latestItemsExcludes.add(latestItemsExcludesItem);
        return this;
    }

    /**
     * Get latestItemsExcludes
     * 
     * @return latestItemsExcludes
     */
    @JsonProperty(value = JSON_PROPERTY_LATEST_ITEMS_EXCLUDES)
    public @org.eclipse.jdt.annotation.Nullable List<UUID> getLatestItemsExcludes() {
        return latestItemsExcludes;
    }

    @JsonProperty(value = JSON_PROPERTY_LATEST_ITEMS_EXCLUDES)
    public void setLatestItemsExcludes(@org.eclipse.jdt.annotation.Nullable List<UUID> latestItemsExcludes) {
        this.latestItemsExcludes = latestItemsExcludes;
    }

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

    public UserConfiguration addMyMediaExcludesItem(UUID myMediaExcludesItem) {
        if (this.myMediaExcludes == null) {
            this.myMediaExcludes = new ArrayList<>();
        }
        this.myMediaExcludes.add(myMediaExcludesItem);
        return this;
    }

    /**
     * Get myMediaExcludes
     * 
     * @return myMediaExcludes
     */
    @JsonProperty(value = JSON_PROPERTY_MY_MEDIA_EXCLUDES)
    public @org.eclipse.jdt.annotation.Nullable List<UUID> getMyMediaExcludes() {
        return myMediaExcludes;
    }

    @JsonProperty(value = JSON_PROPERTY_MY_MEDIA_EXCLUDES)
    public void setMyMediaExcludes(@org.eclipse.jdt.annotation.Nullable List<UUID> myMediaExcludes) {
        this.myMediaExcludes = myMediaExcludes;
    }

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

    /**
     * Get hidePlayedInLatest
     * 
     * @return hidePlayedInLatest
     */
    @JsonProperty(value = JSON_PROPERTY_HIDE_PLAYED_IN_LATEST)
    public @org.eclipse.jdt.annotation.Nullable Boolean getHidePlayedInLatest() {
        return hidePlayedInLatest;
    }

    @JsonProperty(value = JSON_PROPERTY_HIDE_PLAYED_IN_LATEST)
    public void setHidePlayedInLatest(@org.eclipse.jdt.annotation.Nullable Boolean hidePlayedInLatest) {
        this.hidePlayedInLatest = hidePlayedInLatest;
    }

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

    /**
     * Get rememberAudioSelections
     * 
     * @return rememberAudioSelections
     */
    @JsonProperty(value = JSON_PROPERTY_REMEMBER_AUDIO_SELECTIONS)
    public @org.eclipse.jdt.annotation.Nullable Boolean getRememberAudioSelections() {
        return rememberAudioSelections;
    }

    @JsonProperty(value = JSON_PROPERTY_REMEMBER_AUDIO_SELECTIONS)
    public void setRememberAudioSelections(@org.eclipse.jdt.annotation.Nullable Boolean rememberAudioSelections) {
        this.rememberAudioSelections = rememberAudioSelections;
    }

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

    /**
     * Get rememberSubtitleSelections
     * 
     * @return rememberSubtitleSelections
     */
    @JsonProperty(value = JSON_PROPERTY_REMEMBER_SUBTITLE_SELECTIONS)
    public @org.eclipse.jdt.annotation.Nullable Boolean getRememberSubtitleSelections() {
        return rememberSubtitleSelections;
    }

    @JsonProperty(value = JSON_PROPERTY_REMEMBER_SUBTITLE_SELECTIONS)
    public void setRememberSubtitleSelections(@org.eclipse.jdt.annotation.Nullable Boolean rememberSubtitleSelections) {
        this.rememberSubtitleSelections = rememberSubtitleSelections;
    }

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

    /**
     * Get enableNextEpisodeAutoPlay
     * 
     * @return enableNextEpisodeAutoPlay
     */
    @JsonProperty(value = JSON_PROPERTY_ENABLE_NEXT_EPISODE_AUTO_PLAY)
    public @org.eclipse.jdt.annotation.Nullable Boolean getEnableNextEpisodeAutoPlay() {
        return enableNextEpisodeAutoPlay;
    }

    @JsonProperty(value = JSON_PROPERTY_ENABLE_NEXT_EPISODE_AUTO_PLAY)
    public void setEnableNextEpisodeAutoPlay(@org.eclipse.jdt.annotation.Nullable Boolean enableNextEpisodeAutoPlay) {
        this.enableNextEpisodeAutoPlay = enableNextEpisodeAutoPlay;
    }

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

    /**
     * Gets or sets the id of the selected cast receiver.
     * 
     * @return castReceiverId
     */
    @JsonProperty(value = JSON_PROPERTY_CAST_RECEIVER_ID)
    public @org.eclipse.jdt.annotation.Nullable String getCastReceiverId() {
        return castReceiverId;
    }

    @JsonProperty(value = JSON_PROPERTY_CAST_RECEIVER_ID)
    public void setCastReceiverId(@org.eclipse.jdt.annotation.Nullable String castReceiverId) {
        this.castReceiverId = castReceiverId;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        UserConfiguration userConfiguration = (UserConfiguration) o;
        return Objects.equals(this.audioLanguagePreference, userConfiguration.audioLanguagePreference)
                && Objects.equals(this.playDefaultAudioTrack, userConfiguration.playDefaultAudioTrack)
                && Objects.equals(this.subtitleLanguagePreference, userConfiguration.subtitleLanguagePreference)
                && Objects.equals(this.displayMissingEpisodes, userConfiguration.displayMissingEpisodes)
                && Objects.equals(this.groupedFolders, userConfiguration.groupedFolders)
                && Objects.equals(this.subtitleMode, userConfiguration.subtitleMode)
                && Objects.equals(this.displayCollectionsView, userConfiguration.displayCollectionsView)
                && Objects.equals(this.enableLocalPassword, userConfiguration.enableLocalPassword)
                && Objects.equals(this.orderedViews, userConfiguration.orderedViews)
                && Objects.equals(this.latestItemsExcludes, userConfiguration.latestItemsExcludes)
                && Objects.equals(this.myMediaExcludes, userConfiguration.myMediaExcludes)
                && Objects.equals(this.hidePlayedInLatest, userConfiguration.hidePlayedInLatest)
                && Objects.equals(this.rememberAudioSelections, userConfiguration.rememberAudioSelections)
                && Objects.equals(this.rememberSubtitleSelections, userConfiguration.rememberSubtitleSelections)
                && Objects.equals(this.enableNextEpisodeAutoPlay, userConfiguration.enableNextEpisodeAutoPlay)
                && Objects.equals(this.castReceiverId, userConfiguration.castReceiverId);
    }

    @Override
    public int hashCode() {
        return Objects.hash(audioLanguagePreference, playDefaultAudioTrack, subtitleLanguagePreference,
                displayMissingEpisodes, groupedFolders, subtitleMode, displayCollectionsView, enableLocalPassword,
                orderedViews, latestItemsExcludes, myMediaExcludes, hidePlayedInLatest, rememberAudioSelections,
                rememberSubtitleSelections, enableNextEpisodeAutoPlay, castReceiverId);
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("class UserConfiguration {\n");
        sb.append("    audioLanguagePreference: ").append(toIndentedString(audioLanguagePreference)).append("\n");
        sb.append("    playDefaultAudioTrack: ").append(toIndentedString(playDefaultAudioTrack)).append("\n");
        sb.append("    subtitleLanguagePreference: ").append(toIndentedString(subtitleLanguagePreference)).append("\n");
        sb.append("    displayMissingEpisodes: ").append(toIndentedString(displayMissingEpisodes)).append("\n");
        sb.append("    groupedFolders: ").append(toIndentedString(groupedFolders)).append("\n");
        sb.append("    subtitleMode: ").append(toIndentedString(subtitleMode)).append("\n");
        sb.append("    displayCollectionsView: ").append(toIndentedString(displayCollectionsView)).append("\n");
        sb.append("    enableLocalPassword: ").append(toIndentedString(enableLocalPassword)).append("\n");
        sb.append("    orderedViews: ").append(toIndentedString(orderedViews)).append("\n");
        sb.append("    latestItemsExcludes: ").append(toIndentedString(latestItemsExcludes)).append("\n");
        sb.append("    myMediaExcludes: ").append(toIndentedString(myMediaExcludes)).append("\n");
        sb.append("    hidePlayedInLatest: ").append(toIndentedString(hidePlayedInLatest)).append("\n");
        sb.append("    rememberAudioSelections: ").append(toIndentedString(rememberAudioSelections)).append("\n");
        sb.append("    rememberSubtitleSelections: ").append(toIndentedString(rememberSubtitleSelections)).append("\n");
        sb.append("    enableNextEpisodeAutoPlay: ").append(toIndentedString(enableNextEpisodeAutoPlay)).append("\n");
        sb.append("    castReceiverId: ").append(toIndentedString(castReceiverId)).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 `AudioLanguagePreference` to the URL query string
        if (getAudioLanguagePreference() != null) {
            try {
                joiner.add(String.format(java.util.Locale.ROOT, "%sAudioLanguagePreference%s=%s", prefix, suffix,
                        URLEncoder.encode(String.valueOf(getAudioLanguagePreference()), "UTF-8").replaceAll("\\+",
                                "%20")));
            } catch (UnsupportedEncodingException e) {
                // Should never happen, UTF-8 is always supported
                throw new RuntimeException(e);
            }
        }

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

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

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

        // add `GroupedFolders` to the URL query string
        if (getGroupedFolders() != null) {
            for (int i = 0; i < getGroupedFolders().size(); i++) {
                if (getGroupedFolders().get(i) != null) {
                    try {
                        joiner.add(String.format(java.util.Locale.ROOT, "%sGroupedFolders%s%s=%s", prefix, suffix,
                                "".equals(suffix) ? ""
                                        : String.format(java.util.Locale.ROOT, "%s%d%s", containerPrefix, i,
                                                containerSuffix),
                                URLEncoder.encode(String.valueOf(getGroupedFolders().get(i)), "UTF-8").replaceAll("\\+",
                                        "%20")));
                    } catch (UnsupportedEncodingException e) {
                        // Should never happen, UTF-8 is always supported
                        throw new RuntimeException(e);
                    }
                }
            }
        }

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

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

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

        // add `OrderedViews` to the URL query string
        if (getOrderedViews() != null) {
            for (int i = 0; i < getOrderedViews().size(); i++) {
                if (getOrderedViews().get(i) != null) {
                    try {
                        joiner.add(String.format(java.util.Locale.ROOT, "%sOrderedViews%s%s=%s", prefix, suffix,
                                "".equals(suffix) ? ""
                                        : String.format(java.util.Locale.ROOT, "%s%d%s", containerPrefix, i,
                                                containerSuffix),
                                URLEncoder.encode(String.valueOf(getOrderedViews().get(i)), "UTF-8").replaceAll("\\+",
                                        "%20")));
                    } catch (UnsupportedEncodingException e) {
                        // Should never happen, UTF-8 is always supported
                        throw new RuntimeException(e);
                    }
                }
            }
        }

        // add `LatestItemsExcludes` to the URL query string
        if (getLatestItemsExcludes() != null) {
            for (int i = 0; i < getLatestItemsExcludes().size(); i++) {
                if (getLatestItemsExcludes().get(i) != null) {
                    try {
                        joiner.add(String.format(java.util.Locale.ROOT, "%sLatestItemsExcludes%s%s=%s", prefix, suffix,
                                "".equals(suffix) ? ""
                                        : String.format(java.util.Locale.ROOT, "%s%d%s", containerPrefix, i,
                                                containerSuffix),
                                URLEncoder.encode(String.valueOf(getLatestItemsExcludes().get(i)), "UTF-8")
                                        .replaceAll("\\+", "%20")));
                    } catch (UnsupportedEncodingException e) {
                        // Should never happen, UTF-8 is always supported
                        throw new RuntimeException(e);
                    }
                }
            }
        }

        // add `MyMediaExcludes` to the URL query string
        if (getMyMediaExcludes() != null) {
            for (int i = 0; i < getMyMediaExcludes().size(); i++) {
                if (getMyMediaExcludes().get(i) != null) {
                    try {
                        joiner.add(String.format(java.util.Locale.ROOT, "%sMyMediaExcludes%s%s=%s", prefix, suffix,
                                "".equals(suffix) ? ""
                                        : String.format(java.util.Locale.ROOT, "%s%d%s", containerPrefix, i,
                                                containerSuffix),
                                URLEncoder.encode(String.valueOf(getMyMediaExcludes().get(i)), "UTF-8")
                                        .replaceAll("\\+", "%20")));
                    } catch (UnsupportedEncodingException e) {
                        // Should never happen, UTF-8 is always supported
                        throw new RuntimeException(e);
                    }
                }
            }
        }

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

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

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

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

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

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

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

        public UserConfiguration.Builder audioLanguagePreference(String audioLanguagePreference) {
            this.instance.audioLanguagePreference = audioLanguagePreference;
            return this;
        }

        public UserConfiguration.Builder playDefaultAudioTrack(Boolean playDefaultAudioTrack) {
            this.instance.playDefaultAudioTrack = playDefaultAudioTrack;
            return this;
        }

        public UserConfiguration.Builder subtitleLanguagePreference(String subtitleLanguagePreference) {
            this.instance.subtitleLanguagePreference = subtitleLanguagePreference;
            return this;
        }

        public UserConfiguration.Builder displayMissingEpisodes(Boolean displayMissingEpisodes) {
            this.instance.displayMissingEpisodes = displayMissingEpisodes;
            return this;
        }

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

        public UserConfiguration.Builder subtitleMode(SubtitlePlaybackMode subtitleMode) {
            this.instance.subtitleMode = subtitleMode;
            return this;
        }

        public UserConfiguration.Builder displayCollectionsView(Boolean displayCollectionsView) {
            this.instance.displayCollectionsView = displayCollectionsView;
            return this;
        }

        public UserConfiguration.Builder enableLocalPassword(Boolean enableLocalPassword) {
            this.instance.enableLocalPassword = enableLocalPassword;
            return this;
        }

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

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

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

        public UserConfiguration.Builder hidePlayedInLatest(Boolean hidePlayedInLatest) {
            this.instance.hidePlayedInLatest = hidePlayedInLatest;
            return this;
        }

        public UserConfiguration.Builder rememberAudioSelections(Boolean rememberAudioSelections) {
            this.instance.rememberAudioSelections = rememberAudioSelections;
            return this;
        }

        public UserConfiguration.Builder rememberSubtitleSelections(Boolean rememberSubtitleSelections) {
            this.instance.rememberSubtitleSelections = rememberSubtitleSelections;
            return this;
        }

        public UserConfiguration.Builder enableNextEpisodeAutoPlay(Boolean enableNextEpisodeAutoPlay) {
            this.instance.enableNextEpisodeAutoPlay = enableNextEpisodeAutoPlay;
            return this;
        }

        public UserConfiguration.Builder castReceiverId(String castReceiverId) {
            this.instance.castReceiverId = castReceiverId;
            return this;
        }

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

    /**
     * Create a builder with a shallow copy of this instance.
     */
    public UserConfiguration.Builder toBuilder() {
        return new UserConfiguration.Builder().audioLanguagePreference(getAudioLanguagePreference())
                .playDefaultAudioTrack(getPlayDefaultAudioTrack())
                .subtitleLanguagePreference(getSubtitleLanguagePreference())
                .displayMissingEpisodes(getDisplayMissingEpisodes()).groupedFolders(getGroupedFolders())
                .subtitleMode(getSubtitleMode()).displayCollectionsView(getDisplayCollectionsView())
                .enableLocalPassword(getEnableLocalPassword()).orderedViews(getOrderedViews())
                .latestItemsExcludes(getLatestItemsExcludes()).myMediaExcludes(getMyMediaExcludes())
                .hidePlayedInLatest(getHidePlayedInLatest()).rememberAudioSelections(getRememberAudioSelections())
                .rememberSubtitleSelections(getRememberSubtitleSelections())
                .enableNextEpisodeAutoPlay(getEnableNextEpisodeAutoPlay()).castReceiverId(getCastReceiverId());
    }
}
