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

/**
 * LiveTvInfo
 */
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "OpenAPI Generator")
public class LiveTvInfo {
    public static final String JSON_PROPERTY_SERVICES = "Services";
    private @org.eclipse.jdt.annotation.Nullable List<LiveTvServiceInfo> services = new ArrayList<>();

    public static final String JSON_PROPERTY_IS_ENABLED = "IsEnabled";
    private @org.eclipse.jdt.annotation.Nullable Boolean isEnabled;

    public static final String JSON_PROPERTY_ENABLED_USERS = "EnabledUsers";
    private @org.eclipse.jdt.annotation.Nullable List<String> enabledUsers = new ArrayList<>();

    public LiveTvInfo() {
    }

    public LiveTvInfo services(@org.eclipse.jdt.annotation.Nullable List<LiveTvServiceInfo> services) {
        this.services = services;
        return this;
    }

    public LiveTvInfo addServicesItem(LiveTvServiceInfo servicesItem) {
        if (this.services == null) {
            this.services = new ArrayList<>();
        }
        this.services.add(servicesItem);
        return this;
    }

    /**
     * Gets or sets the services.
     * 
     * @return services
     */
    @JsonProperty(value = JSON_PROPERTY_SERVICES)
    public @org.eclipse.jdt.annotation.Nullable List<LiveTvServiceInfo> getServices() {
        return services;
    }

    @JsonProperty(value = JSON_PROPERTY_SERVICES)
    public void setServices(@org.eclipse.jdt.annotation.Nullable List<LiveTvServiceInfo> services) {
        this.services = services;
    }

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

    /**
     * Gets or sets a value indicating whether this instance is enabled.
     * 
     * @return isEnabled
     */
    @JsonProperty(value = JSON_PROPERTY_IS_ENABLED)
    public @org.eclipse.jdt.annotation.Nullable Boolean getIsEnabled() {
        return isEnabled;
    }

    @JsonProperty(value = JSON_PROPERTY_IS_ENABLED)
    public void setIsEnabled(@org.eclipse.jdt.annotation.Nullable Boolean isEnabled) {
        this.isEnabled = isEnabled;
    }

    public LiveTvInfo enabledUsers(@org.eclipse.jdt.annotation.Nullable List<String> enabledUsers) {
        this.enabledUsers = enabledUsers;
        return this;
    }

    public LiveTvInfo addEnabledUsersItem(String enabledUsersItem) {
        if (this.enabledUsers == null) {
            this.enabledUsers = new ArrayList<>();
        }
        this.enabledUsers.add(enabledUsersItem);
        return this;
    }

    /**
     * Gets or sets the enabled users.
     * 
     * @return enabledUsers
     */
    @JsonProperty(value = JSON_PROPERTY_ENABLED_USERS)
    public @org.eclipse.jdt.annotation.Nullable List<String> getEnabledUsers() {
        return enabledUsers;
    }

    @JsonProperty(value = JSON_PROPERTY_ENABLED_USERS)
    public void setEnabledUsers(@org.eclipse.jdt.annotation.Nullable List<String> enabledUsers) {
        this.enabledUsers = enabledUsers;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        LiveTvInfo liveTvInfo = (LiveTvInfo) o;
        return Objects.equals(this.services, liveTvInfo.services)
                && Objects.equals(this.isEnabled, liveTvInfo.isEnabled)
                && Objects.equals(this.enabledUsers, liveTvInfo.enabledUsers);
    }

    @Override
    public int hashCode() {
        return Objects.hash(services, isEnabled, enabledUsers);
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("class LiveTvInfo {\n");
        sb.append("    services: ").append(toIndentedString(services)).append("\n");
        sb.append("    isEnabled: ").append(toIndentedString(isEnabled)).append("\n");
        sb.append("    enabledUsers: ").append(toIndentedString(enabledUsers)).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 `Services` to the URL query string
        if (getServices() != null) {
            for (int i = 0; i < getServices().size(); i++) {
                if (getServices().get(i) != null) {
                    joiner.add(getServices().get(i)
                            .toUrlQueryString(String.format(java.util.Locale.ROOT, "%sServices%s%s", prefix, suffix,
                                    "".equals(suffix) ? ""
                                            : String.format(java.util.Locale.ROOT, "%s%d%s", containerPrefix, i,
                                                    containerSuffix))));
                }
            }
        }

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

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

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

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

        public LiveTvInfo.Builder services(List<LiveTvServiceInfo> services) {
            this.instance.services = services;
            return this;
        }

        public LiveTvInfo.Builder isEnabled(Boolean isEnabled) {
            this.instance.isEnabled = isEnabled;
            return this;
        }

        public LiveTvInfo.Builder enabledUsers(List<String> enabledUsers) {
            this.instance.enabledUsers = enabledUsers;
            return this;
        }

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

    /**
     * Create a builder with a shallow copy of this instance.
     */
    public LiveTvInfo.Builder toBuilder() {
        return new LiveTvInfo.Builder().services(getServices()).isEnabled(getIsEnabled())
                .enabledUsers(getEnabledUsers());
    }
}
