/*
 * 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.Objects;
import java.util.StringJoiner;

import com.fasterxml.jackson.annotation.JsonProperty;

/**
 * Options to configure jellyfins managed database.
 */
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "OpenAPI Generator")
public class DatabaseConfigurationOptions {
    public static final String JSON_PROPERTY_DATABASE_TYPE = "DatabaseType";
    private @org.eclipse.jdt.annotation.Nullable String databaseType;

    public static final String JSON_PROPERTY_CUSTOM_PROVIDER_OPTIONS = "CustomProviderOptions";
    private @org.eclipse.jdt.annotation.Nullable CustomDatabaseOptions customProviderOptions;

    public static final String JSON_PROPERTY_LOCKING_BEHAVIOR = "LockingBehavior";
    private @org.eclipse.jdt.annotation.Nullable DatabaseLockingBehaviorTypes lockingBehavior;

    public DatabaseConfigurationOptions() {
    }

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

    /**
     * Gets or Sets the type of database jellyfin should use.
     * 
     * @return databaseType
     */
    @JsonProperty(value = JSON_PROPERTY_DATABASE_TYPE)
    public @org.eclipse.jdt.annotation.Nullable String getDatabaseType() {
        return databaseType;
    }

    @JsonProperty(value = JSON_PROPERTY_DATABASE_TYPE)
    public void setDatabaseType(@org.eclipse.jdt.annotation.Nullable String databaseType) {
        this.databaseType = databaseType;
    }

    public DatabaseConfigurationOptions customProviderOptions(
            @org.eclipse.jdt.annotation.Nullable CustomDatabaseOptions customProviderOptions) {
        this.customProviderOptions = customProviderOptions;
        return this;
    }

    /**
     * Gets or sets the options required to use a custom database provider.
     * 
     * @return customProviderOptions
     */
    @JsonProperty(value = JSON_PROPERTY_CUSTOM_PROVIDER_OPTIONS)
    public @org.eclipse.jdt.annotation.Nullable CustomDatabaseOptions getCustomProviderOptions() {
        return customProviderOptions;
    }

    @JsonProperty(value = JSON_PROPERTY_CUSTOM_PROVIDER_OPTIONS)
    public void setCustomProviderOptions(
            @org.eclipse.jdt.annotation.Nullable CustomDatabaseOptions customProviderOptions) {
        this.customProviderOptions = customProviderOptions;
    }

    public DatabaseConfigurationOptions lockingBehavior(
            @org.eclipse.jdt.annotation.Nullable DatabaseLockingBehaviorTypes lockingBehavior) {
        this.lockingBehavior = lockingBehavior;
        return this;
    }

    /**
     * Gets or Sets the kind of locking behavior jellyfin should perform. Possible options are \&quot;NoLock\&quot;,
     * \&quot;Pessimistic\&quot;, \&quot;Optimistic\&quot;. Defaults to \&quot;NoLock\&quot;.
     * 
     * @return lockingBehavior
     */
    @JsonProperty(value = JSON_PROPERTY_LOCKING_BEHAVIOR)
    public @org.eclipse.jdt.annotation.Nullable DatabaseLockingBehaviorTypes getLockingBehavior() {
        return lockingBehavior;
    }

    @JsonProperty(value = JSON_PROPERTY_LOCKING_BEHAVIOR)
    public void setLockingBehavior(@org.eclipse.jdt.annotation.Nullable DatabaseLockingBehaviorTypes lockingBehavior) {
        this.lockingBehavior = lockingBehavior;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        DatabaseConfigurationOptions databaseConfigurationOptions = (DatabaseConfigurationOptions) o;
        return Objects.equals(this.databaseType, databaseConfigurationOptions.databaseType)
                && Objects.equals(this.customProviderOptions, databaseConfigurationOptions.customProviderOptions)
                && Objects.equals(this.lockingBehavior, databaseConfigurationOptions.lockingBehavior);
    }

    @Override
    public int hashCode() {
        return Objects.hash(databaseType, customProviderOptions, lockingBehavior);
    }

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

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

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

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

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

        public DatabaseConfigurationOptions.Builder databaseType(String databaseType) {
            this.instance.databaseType = databaseType;
            return this;
        }

        public DatabaseConfigurationOptions.Builder customProviderOptions(CustomDatabaseOptions customProviderOptions) {
            this.instance.customProviderOptions = customProviderOptions;
            return this;
        }

        public DatabaseConfigurationOptions.Builder lockingBehavior(DatabaseLockingBehaviorTypes lockingBehavior) {
            this.instance.lockingBehavior = lockingBehavior;
            return this;
        }

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

    /**
     * Create a builder with a shallow copy of this instance.
     */
    public DatabaseConfigurationOptions.Builder toBuilder() {
        return new DatabaseConfigurationOptions.Builder().databaseType(getDatabaseType())
                .customProviderOptions(getCustomProviderOptions()).lockingBehavior(getLockingBehavior());
    }
}
