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

/**
 * Defines the MediaBrowser.Model.Dlna.CodecProfile.
 */
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "OpenAPI Generator")
public class CodecProfile {
    public static final String JSON_PROPERTY_TYPE = "Type";
    private @org.eclipse.jdt.annotation.Nullable CodecType type;

    public static final String JSON_PROPERTY_CONDITIONS = "Conditions";
    private @org.eclipse.jdt.annotation.Nullable List<ProfileCondition> conditions = new ArrayList<>();

    public static final String JSON_PROPERTY_APPLY_CONDITIONS = "ApplyConditions";
    private @org.eclipse.jdt.annotation.Nullable List<ProfileCondition> applyConditions = new ArrayList<>();

    public static final String JSON_PROPERTY_CODEC = "Codec";
    private @org.eclipse.jdt.annotation.Nullable String codec;

    public static final String JSON_PROPERTY_CONTAINER = "Container";
    private @org.eclipse.jdt.annotation.Nullable String container;

    public static final String JSON_PROPERTY_SUB_CONTAINER = "SubContainer";
    private @org.eclipse.jdt.annotation.Nullable String subContainer;

    public CodecProfile() {
    }

    public CodecProfile type(@org.eclipse.jdt.annotation.Nullable CodecType type) {
        this.type = type;
        return this;
    }

    /**
     * Gets or sets the MediaBrowser.Model.Dlna.CodecType which this container must meet.
     * 
     * @return type
     */
    @JsonProperty(value = JSON_PROPERTY_TYPE)
    public @org.eclipse.jdt.annotation.Nullable CodecType getType() {
        return type;
    }

    @JsonProperty(value = JSON_PROPERTY_TYPE)
    public void setType(@org.eclipse.jdt.annotation.Nullable CodecType type) {
        this.type = type;
    }

    public CodecProfile conditions(@org.eclipse.jdt.annotation.Nullable List<ProfileCondition> conditions) {
        this.conditions = conditions;
        return this;
    }

    public CodecProfile addConditionsItem(ProfileCondition conditionsItem) {
        if (this.conditions == null) {
            this.conditions = new ArrayList<>();
        }
        this.conditions.add(conditionsItem);
        return this;
    }

    /**
     * Gets or sets the list of MediaBrowser.Model.Dlna.ProfileCondition which this profile must meet.
     * 
     * @return conditions
     */
    @JsonProperty(value = JSON_PROPERTY_CONDITIONS)
    public @org.eclipse.jdt.annotation.Nullable List<ProfileCondition> getConditions() {
        return conditions;
    }

    @JsonProperty(value = JSON_PROPERTY_CONDITIONS)
    public void setConditions(@org.eclipse.jdt.annotation.Nullable List<ProfileCondition> conditions) {
        this.conditions = conditions;
    }

    public CodecProfile applyConditions(@org.eclipse.jdt.annotation.Nullable List<ProfileCondition> applyConditions) {
        this.applyConditions = applyConditions;
        return this;
    }

    public CodecProfile addApplyConditionsItem(ProfileCondition applyConditionsItem) {
        if (this.applyConditions == null) {
            this.applyConditions = new ArrayList<>();
        }
        this.applyConditions.add(applyConditionsItem);
        return this;
    }

    /**
     * Gets or sets the list of MediaBrowser.Model.Dlna.ProfileCondition to apply if this profile is met.
     * 
     * @return applyConditions
     */
    @JsonProperty(value = JSON_PROPERTY_APPLY_CONDITIONS)
    public @org.eclipse.jdt.annotation.Nullable List<ProfileCondition> getApplyConditions() {
        return applyConditions;
    }

    @JsonProperty(value = JSON_PROPERTY_APPLY_CONDITIONS)
    public void setApplyConditions(@org.eclipse.jdt.annotation.Nullable List<ProfileCondition> applyConditions) {
        this.applyConditions = applyConditions;
    }

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

    /**
     * Gets or sets the codec(s) that this profile applies to.
     * 
     * @return codec
     */
    @JsonProperty(value = JSON_PROPERTY_CODEC)
    public @org.eclipse.jdt.annotation.Nullable String getCodec() {
        return codec;
    }

    @JsonProperty(value = JSON_PROPERTY_CODEC)
    public void setCodec(@org.eclipse.jdt.annotation.Nullable String codec) {
        this.codec = codec;
    }

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

    /**
     * Gets or sets the container(s) which this profile will be applied to.
     * 
     * @return container
     */
    @JsonProperty(value = JSON_PROPERTY_CONTAINER)
    public @org.eclipse.jdt.annotation.Nullable String getContainer() {
        return container;
    }

    @JsonProperty(value = JSON_PROPERTY_CONTAINER)
    public void setContainer(@org.eclipse.jdt.annotation.Nullable String container) {
        this.container = container;
    }

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

    /**
     * Gets or sets the sub-container(s) which this profile will be applied to.
     * 
     * @return subContainer
     */
    @JsonProperty(value = JSON_PROPERTY_SUB_CONTAINER)
    public @org.eclipse.jdt.annotation.Nullable String getSubContainer() {
        return subContainer;
    }

    @JsonProperty(value = JSON_PROPERTY_SUB_CONTAINER)
    public void setSubContainer(@org.eclipse.jdt.annotation.Nullable String subContainer) {
        this.subContainer = subContainer;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        CodecProfile codecProfile = (CodecProfile) o;
        return Objects.equals(this.type, codecProfile.type) && Objects.equals(this.conditions, codecProfile.conditions)
                && Objects.equals(this.applyConditions, codecProfile.applyConditions)
                && Objects.equals(this.codec, codecProfile.codec)
                && Objects.equals(this.container, codecProfile.container)
                && Objects.equals(this.subContainer, codecProfile.subContainer);
    }

    @Override
    public int hashCode() {
        return Objects.hash(type, conditions, applyConditions, codec, container, subContainer);
    }

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

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

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

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

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

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

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

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

        public CodecProfile.Builder type(CodecType type) {
            this.instance.type = type;
            return this;
        }

        public CodecProfile.Builder conditions(List<ProfileCondition> conditions) {
            this.instance.conditions = conditions;
            return this;
        }

        public CodecProfile.Builder applyConditions(List<ProfileCondition> applyConditions) {
            this.instance.applyConditions = applyConditions;
            return this;
        }

        public CodecProfile.Builder codec(String codec) {
            this.instance.codec = codec;
            return this;
        }

        public CodecProfile.Builder container(String container) {
            this.instance.container = container;
            return this;
        }

        public CodecProfile.Builder subContainer(String subContainer) {
            this.instance.subContainer = subContainer;
            return this;
        }

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

    /**
     * Create a builder with a shallow copy of this instance.
     */
    public CodecProfile.Builder toBuilder() {
        return new CodecProfile.Builder().type(getType()).conditions(getConditions())
                .applyConditions(getApplyConditions()).codec(getCodec()).container(getContainer())
                .subContainer(getSubContainer());
    }
}
