/*
 * 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 com.fasterxml.jackson.annotation.JsonProperty;

/**
 * Client capabilities dto.
 */
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "OpenAPI Generator")
public class ClientCapabilitiesDto {
    public static final String JSON_PROPERTY_PLAYABLE_MEDIA_TYPES = "PlayableMediaTypes";
    private @org.eclipse.jdt.annotation.Nullable List<MediaType> playableMediaTypes = new ArrayList<>();

    public static final String JSON_PROPERTY_SUPPORTED_COMMANDS = "SupportedCommands";
    private @org.eclipse.jdt.annotation.Nullable List<GeneralCommandType> supportedCommands = new ArrayList<>();

    public static final String JSON_PROPERTY_SUPPORTS_MEDIA_CONTROL = "SupportsMediaControl";
    private @org.eclipse.jdt.annotation.Nullable Boolean supportsMediaControl;

    public static final String JSON_PROPERTY_SUPPORTS_PERSISTENT_IDENTIFIER = "SupportsPersistentIdentifier";
    private @org.eclipse.jdt.annotation.Nullable Boolean supportsPersistentIdentifier;

    public static final String JSON_PROPERTY_DEVICE_PROFILE = "DeviceProfile";
    private @org.eclipse.jdt.annotation.Nullable DeviceProfile deviceProfile;

    public static final String JSON_PROPERTY_APP_STORE_URL = "AppStoreUrl";
    private @org.eclipse.jdt.annotation.Nullable String appStoreUrl;

    public static final String JSON_PROPERTY_ICON_URL = "IconUrl";
    private @org.eclipse.jdt.annotation.Nullable String iconUrl;

    public ClientCapabilitiesDto() {
    }

    public ClientCapabilitiesDto playableMediaTypes(
            @org.eclipse.jdt.annotation.Nullable List<MediaType> playableMediaTypes) {
        this.playableMediaTypes = playableMediaTypes;
        return this;
    }

    public ClientCapabilitiesDto addPlayableMediaTypesItem(MediaType playableMediaTypesItem) {
        if (this.playableMediaTypes == null) {
            this.playableMediaTypes = new ArrayList<>();
        }
        this.playableMediaTypes.add(playableMediaTypesItem);
        return this;
    }

    /**
     * Gets or sets the list of playable media types.
     * 
     * @return playableMediaTypes
     */
    @JsonProperty(value = JSON_PROPERTY_PLAYABLE_MEDIA_TYPES)
    public @org.eclipse.jdt.annotation.Nullable List<MediaType> getPlayableMediaTypes() {
        return playableMediaTypes;
    }

    @JsonProperty(value = JSON_PROPERTY_PLAYABLE_MEDIA_TYPES)
    public void setPlayableMediaTypes(@org.eclipse.jdt.annotation.Nullable List<MediaType> playableMediaTypes) {
        this.playableMediaTypes = playableMediaTypes;
    }

    public ClientCapabilitiesDto supportedCommands(
            @org.eclipse.jdt.annotation.Nullable List<GeneralCommandType> supportedCommands) {
        this.supportedCommands = supportedCommands;
        return this;
    }

    public ClientCapabilitiesDto addSupportedCommandsItem(GeneralCommandType supportedCommandsItem) {
        if (this.supportedCommands == null) {
            this.supportedCommands = new ArrayList<>();
        }
        this.supportedCommands.add(supportedCommandsItem);
        return this;
    }

    /**
     * Gets or sets the list of supported commands.
     * 
     * @return supportedCommands
     */
    @JsonProperty(value = JSON_PROPERTY_SUPPORTED_COMMANDS)
    public @org.eclipse.jdt.annotation.Nullable List<GeneralCommandType> getSupportedCommands() {
        return supportedCommands;
    }

    @JsonProperty(value = JSON_PROPERTY_SUPPORTED_COMMANDS)
    public void setSupportedCommands(@org.eclipse.jdt.annotation.Nullable List<GeneralCommandType> supportedCommands) {
        this.supportedCommands = supportedCommands;
    }

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

    /**
     * Gets or sets a value indicating whether session supports media control.
     * 
     * @return supportsMediaControl
     */
    @JsonProperty(value = JSON_PROPERTY_SUPPORTS_MEDIA_CONTROL)
    public @org.eclipse.jdt.annotation.Nullable Boolean getSupportsMediaControl() {
        return supportsMediaControl;
    }

    @JsonProperty(value = JSON_PROPERTY_SUPPORTS_MEDIA_CONTROL)
    public void setSupportsMediaControl(@org.eclipse.jdt.annotation.Nullable Boolean supportsMediaControl) {
        this.supportsMediaControl = supportsMediaControl;
    }

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

    /**
     * Gets or sets a value indicating whether session supports a persistent identifier.
     * 
     * @return supportsPersistentIdentifier
     */
    @JsonProperty(value = JSON_PROPERTY_SUPPORTS_PERSISTENT_IDENTIFIER)
    public @org.eclipse.jdt.annotation.Nullable Boolean getSupportsPersistentIdentifier() {
        return supportsPersistentIdentifier;
    }

    @JsonProperty(value = JSON_PROPERTY_SUPPORTS_PERSISTENT_IDENTIFIER)
    public void setSupportsPersistentIdentifier(
            @org.eclipse.jdt.annotation.Nullable Boolean supportsPersistentIdentifier) {
        this.supportsPersistentIdentifier = supportsPersistentIdentifier;
    }

    public ClientCapabilitiesDto deviceProfile(@org.eclipse.jdt.annotation.Nullable DeviceProfile deviceProfile) {
        this.deviceProfile = deviceProfile;
        return this;
    }

    /**
     * Gets or sets the device profile.
     * 
     * @return deviceProfile
     */
    @JsonProperty(value = JSON_PROPERTY_DEVICE_PROFILE)
    public @org.eclipse.jdt.annotation.Nullable DeviceProfile getDeviceProfile() {
        return deviceProfile;
    }

    @JsonProperty(value = JSON_PROPERTY_DEVICE_PROFILE)
    public void setDeviceProfile(@org.eclipse.jdt.annotation.Nullable DeviceProfile deviceProfile) {
        this.deviceProfile = deviceProfile;
    }

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

    /**
     * Gets or sets the app store url.
     * 
     * @return appStoreUrl
     */
    @JsonProperty(value = JSON_PROPERTY_APP_STORE_URL)
    public @org.eclipse.jdt.annotation.Nullable String getAppStoreUrl() {
        return appStoreUrl;
    }

    @JsonProperty(value = JSON_PROPERTY_APP_STORE_URL)
    public void setAppStoreUrl(@org.eclipse.jdt.annotation.Nullable String appStoreUrl) {
        this.appStoreUrl = appStoreUrl;
    }

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

    /**
     * Gets or sets the icon url.
     * 
     * @return iconUrl
     */
    @JsonProperty(value = JSON_PROPERTY_ICON_URL)
    public @org.eclipse.jdt.annotation.Nullable String getIconUrl() {
        return iconUrl;
    }

    @JsonProperty(value = JSON_PROPERTY_ICON_URL)
    public void setIconUrl(@org.eclipse.jdt.annotation.Nullable String iconUrl) {
        this.iconUrl = iconUrl;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        ClientCapabilitiesDto clientCapabilitiesDto = (ClientCapabilitiesDto) o;
        return Objects.equals(this.playableMediaTypes, clientCapabilitiesDto.playableMediaTypes)
                && Objects.equals(this.supportedCommands, clientCapabilitiesDto.supportedCommands)
                && Objects.equals(this.supportsMediaControl, clientCapabilitiesDto.supportsMediaControl)
                && Objects.equals(this.supportsPersistentIdentifier, clientCapabilitiesDto.supportsPersistentIdentifier)
                && Objects.equals(this.deviceProfile, clientCapabilitiesDto.deviceProfile)
                && Objects.equals(this.appStoreUrl, clientCapabilitiesDto.appStoreUrl)
                && Objects.equals(this.iconUrl, clientCapabilitiesDto.iconUrl);
    }

    @Override
    public int hashCode() {
        return Objects.hash(playableMediaTypes, supportedCommands, supportsMediaControl, supportsPersistentIdentifier,
                deviceProfile, appStoreUrl, iconUrl);
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("class ClientCapabilitiesDto {\n");
        sb.append("    playableMediaTypes: ").append(toIndentedString(playableMediaTypes)).append("\n");
        sb.append("    supportedCommands: ").append(toIndentedString(supportedCommands)).append("\n");
        sb.append("    supportsMediaControl: ").append(toIndentedString(supportsMediaControl)).append("\n");
        sb.append("    supportsPersistentIdentifier: ").append(toIndentedString(supportsPersistentIdentifier))
                .append("\n");
        sb.append("    deviceProfile: ").append(toIndentedString(deviceProfile)).append("\n");
        sb.append("    appStoreUrl: ").append(toIndentedString(appStoreUrl)).append("\n");
        sb.append("    iconUrl: ").append(toIndentedString(iconUrl)).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 `PlayableMediaTypes` to the URL query string
        if (getPlayableMediaTypes() != null) {
            for (int i = 0; i < getPlayableMediaTypes().size(); i++) {
                if (getPlayableMediaTypes().get(i) != null) {
                    try {
                        joiner.add(String.format(java.util.Locale.ROOT, "%sPlayableMediaTypes%s%s=%s", prefix, suffix,
                                "".equals(suffix) ? ""
                                        : String.format(java.util.Locale.ROOT, "%s%d%s", containerPrefix, i,
                                                containerSuffix),
                                URLEncoder.encode(String.valueOf(getPlayableMediaTypes().get(i)), "UTF-8")
                                        .replaceAll("\\+", "%20")));
                    } catch (UnsupportedEncodingException e) {
                        // Should never happen, UTF-8 is always supported
                        throw new RuntimeException(e);
                    }
                }
            }
        }

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

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

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

        // add `DeviceProfile` to the URL query string
        if (getDeviceProfile() != null) {
            joiner.add(getDeviceProfile().toUrlQueryString(prefix + "DeviceProfile" + suffix));
        }

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

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

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

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

        public ClientCapabilitiesDto.Builder playableMediaTypes(List<MediaType> playableMediaTypes) {
            this.instance.playableMediaTypes = playableMediaTypes;
            return this;
        }

        public ClientCapabilitiesDto.Builder supportedCommands(List<GeneralCommandType> supportedCommands) {
            this.instance.supportedCommands = supportedCommands;
            return this;
        }

        public ClientCapabilitiesDto.Builder supportsMediaControl(Boolean supportsMediaControl) {
            this.instance.supportsMediaControl = supportsMediaControl;
            return this;
        }

        public ClientCapabilitiesDto.Builder supportsPersistentIdentifier(Boolean supportsPersistentIdentifier) {
            this.instance.supportsPersistentIdentifier = supportsPersistentIdentifier;
            return this;
        }

        public ClientCapabilitiesDto.Builder deviceProfile(DeviceProfile deviceProfile) {
            this.instance.deviceProfile = deviceProfile;
            return this;
        }

        public ClientCapabilitiesDto.Builder appStoreUrl(String appStoreUrl) {
            this.instance.appStoreUrl = appStoreUrl;
            return this;
        }

        public ClientCapabilitiesDto.Builder iconUrl(String iconUrl) {
            this.instance.iconUrl = iconUrl;
            return this;
        }

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

    /**
     * Create a builder with a shallow copy of this instance.
     */
    public ClientCapabilitiesDto.Builder toBuilder() {
        return new ClientCapabilitiesDto.Builder().playableMediaTypes(getPlayableMediaTypes())
                .supportedCommands(getSupportedCommands()).supportsMediaControl(getSupportsMediaControl())
                .supportsPersistentIdentifier(getSupportsPersistentIdentifier()).deviceProfile(getDeviceProfile())
                .appStoreUrl(getAppStoreUrl()).iconUrl(getIconUrl());
    }
}
