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

/**
 * Class TaskInfo.
 */
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "OpenAPI Generator")
public class TaskInfo {
    public static final String JSON_PROPERTY_NAME = "Name";
    private @org.eclipse.jdt.annotation.Nullable String name;

    public static final String JSON_PROPERTY_STATE = "State";
    private @org.eclipse.jdt.annotation.Nullable TaskState state;

    public static final String JSON_PROPERTY_CURRENT_PROGRESS_PERCENTAGE = "CurrentProgressPercentage";
    private @org.eclipse.jdt.annotation.Nullable Double currentProgressPercentage;

    public static final String JSON_PROPERTY_ID = "Id";
    private @org.eclipse.jdt.annotation.Nullable String id;

    public static final String JSON_PROPERTY_LAST_EXECUTION_RESULT = "LastExecutionResult";
    private @org.eclipse.jdt.annotation.Nullable TaskResult lastExecutionResult;

    public static final String JSON_PROPERTY_TRIGGERS = "Triggers";
    private @org.eclipse.jdt.annotation.Nullable List<TaskTriggerInfo> triggers;

    public static final String JSON_PROPERTY_DESCRIPTION = "Description";
    private @org.eclipse.jdt.annotation.Nullable String description;

    public static final String JSON_PROPERTY_CATEGORY = "Category";
    private @org.eclipse.jdt.annotation.Nullable String category;

    public static final String JSON_PROPERTY_IS_HIDDEN = "IsHidden";
    private @org.eclipse.jdt.annotation.Nullable Boolean isHidden;

    public static final String JSON_PROPERTY_KEY = "Key";
    private @org.eclipse.jdt.annotation.Nullable String key;

    public TaskInfo() {
    }

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

    /**
     * Gets or sets the name.
     * 
     * @return name
     */
    @JsonProperty(value = JSON_PROPERTY_NAME)
    public @org.eclipse.jdt.annotation.Nullable String getName() {
        return name;
    }

    @JsonProperty(value = JSON_PROPERTY_NAME)
    public void setName(@org.eclipse.jdt.annotation.Nullable String name) {
        this.name = name;
    }

    public TaskInfo state(@org.eclipse.jdt.annotation.Nullable TaskState state) {
        this.state = state;
        return this;
    }

    /**
     * Gets or sets the state of the task.
     * 
     * @return state
     */
    @JsonProperty(value = JSON_PROPERTY_STATE)
    public @org.eclipse.jdt.annotation.Nullable TaskState getState() {
        return state;
    }

    @JsonProperty(value = JSON_PROPERTY_STATE)
    public void setState(@org.eclipse.jdt.annotation.Nullable TaskState state) {
        this.state = state;
    }

    public TaskInfo currentProgressPercentage(@org.eclipse.jdt.annotation.Nullable Double currentProgressPercentage) {
        this.currentProgressPercentage = currentProgressPercentage;
        return this;
    }

    /**
     * Gets or sets the progress.
     * 
     * @return currentProgressPercentage
     */
    @JsonProperty(value = JSON_PROPERTY_CURRENT_PROGRESS_PERCENTAGE)
    public @org.eclipse.jdt.annotation.Nullable Double getCurrentProgressPercentage() {
        return currentProgressPercentage;
    }

    @JsonProperty(value = JSON_PROPERTY_CURRENT_PROGRESS_PERCENTAGE)
    public void setCurrentProgressPercentage(@org.eclipse.jdt.annotation.Nullable Double currentProgressPercentage) {
        this.currentProgressPercentage = currentProgressPercentage;
    }

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

    /**
     * Gets or sets the id.
     * 
     * @return id
     */
    @JsonProperty(value = JSON_PROPERTY_ID)
    public @org.eclipse.jdt.annotation.Nullable String getId() {
        return id;
    }

    @JsonProperty(value = JSON_PROPERTY_ID)
    public void setId(@org.eclipse.jdt.annotation.Nullable String id) {
        this.id = id;
    }

    public TaskInfo lastExecutionResult(@org.eclipse.jdt.annotation.Nullable TaskResult lastExecutionResult) {
        this.lastExecutionResult = lastExecutionResult;
        return this;
    }

    /**
     * Gets or sets the last execution result.
     * 
     * @return lastExecutionResult
     */
    @JsonProperty(value = JSON_PROPERTY_LAST_EXECUTION_RESULT)
    public @org.eclipse.jdt.annotation.Nullable TaskResult getLastExecutionResult() {
        return lastExecutionResult;
    }

    @JsonProperty(value = JSON_PROPERTY_LAST_EXECUTION_RESULT)
    public void setLastExecutionResult(@org.eclipse.jdt.annotation.Nullable TaskResult lastExecutionResult) {
        this.lastExecutionResult = lastExecutionResult;
    }

    public TaskInfo triggers(@org.eclipse.jdt.annotation.Nullable List<TaskTriggerInfo> triggers) {
        this.triggers = triggers;
        return this;
    }

    public TaskInfo addTriggersItem(TaskTriggerInfo triggersItem) {
        if (this.triggers == null) {
            this.triggers = new ArrayList<>();
        }
        this.triggers.add(triggersItem);
        return this;
    }

    /**
     * Gets or sets the triggers.
     * 
     * @return triggers
     */
    @JsonProperty(value = JSON_PROPERTY_TRIGGERS)
    public @org.eclipse.jdt.annotation.Nullable List<TaskTriggerInfo> getTriggers() {
        return triggers;
    }

    @JsonProperty(value = JSON_PROPERTY_TRIGGERS)
    public void setTriggers(@org.eclipse.jdt.annotation.Nullable List<TaskTriggerInfo> triggers) {
        this.triggers = triggers;
    }

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

    /**
     * Gets or sets the description.
     * 
     * @return description
     */
    @JsonProperty(value = JSON_PROPERTY_DESCRIPTION)
    public @org.eclipse.jdt.annotation.Nullable String getDescription() {
        return description;
    }

    @JsonProperty(value = JSON_PROPERTY_DESCRIPTION)
    public void setDescription(@org.eclipse.jdt.annotation.Nullable String description) {
        this.description = description;
    }

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

    /**
     * Gets or sets the category.
     * 
     * @return category
     */
    @JsonProperty(value = JSON_PROPERTY_CATEGORY)
    public @org.eclipse.jdt.annotation.Nullable String getCategory() {
        return category;
    }

    @JsonProperty(value = JSON_PROPERTY_CATEGORY)
    public void setCategory(@org.eclipse.jdt.annotation.Nullable String category) {
        this.category = category;
    }

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

    /**
     * Gets or sets a value indicating whether this instance is hidden.
     * 
     * @return isHidden
     */
    @JsonProperty(value = JSON_PROPERTY_IS_HIDDEN)
    public @org.eclipse.jdt.annotation.Nullable Boolean getIsHidden() {
        return isHidden;
    }

    @JsonProperty(value = JSON_PROPERTY_IS_HIDDEN)
    public void setIsHidden(@org.eclipse.jdt.annotation.Nullable Boolean isHidden) {
        this.isHidden = isHidden;
    }

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

    /**
     * Gets or sets the key.
     * 
     * @return key
     */
    @JsonProperty(value = JSON_PROPERTY_KEY)
    public @org.eclipse.jdt.annotation.Nullable String getKey() {
        return key;
    }

    @JsonProperty(value = JSON_PROPERTY_KEY)
    public void setKey(@org.eclipse.jdt.annotation.Nullable String key) {
        this.key = key;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        TaskInfo taskInfo = (TaskInfo) o;
        return Objects.equals(this.name, taskInfo.name) && Objects.equals(this.state, taskInfo.state)
                && Objects.equals(this.currentProgressPercentage, taskInfo.currentProgressPercentage)
                && Objects.equals(this.id, taskInfo.id)
                && Objects.equals(this.lastExecutionResult, taskInfo.lastExecutionResult)
                && Objects.equals(this.triggers, taskInfo.triggers)
                && Objects.equals(this.description, taskInfo.description)
                && Objects.equals(this.category, taskInfo.category) && Objects.equals(this.isHidden, taskInfo.isHidden)
                && Objects.equals(this.key, taskInfo.key);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, state, currentProgressPercentage, id, lastExecutionResult, triggers, description,
                category, isHidden, key);
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("class TaskInfo {\n");
        sb.append("    name: ").append(toIndentedString(name)).append("\n");
        sb.append("    state: ").append(toIndentedString(state)).append("\n");
        sb.append("    currentProgressPercentage: ").append(toIndentedString(currentProgressPercentage)).append("\n");
        sb.append("    id: ").append(toIndentedString(id)).append("\n");
        sb.append("    lastExecutionResult: ").append(toIndentedString(lastExecutionResult)).append("\n");
        sb.append("    triggers: ").append(toIndentedString(triggers)).append("\n");
        sb.append("    description: ").append(toIndentedString(description)).append("\n");
        sb.append("    category: ").append(toIndentedString(category)).append("\n");
        sb.append("    isHidden: ").append(toIndentedString(isHidden)).append("\n");
        sb.append("    key: ").append(toIndentedString(key)).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 `Name` to the URL query string
        if (getName() != null) {
            try {
                joiner.add(String.format(java.util.Locale.ROOT, "%sName%s=%s", prefix, suffix,
                        URLEncoder.encode(String.valueOf(getName()), "UTF-8").replaceAll("\\+", "%20")));
            } catch (UnsupportedEncodingException e) {
                // Should never happen, UTF-8 is always supported
                throw new RuntimeException(e);
            }
        }

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

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

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

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

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

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

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

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

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

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

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

        public TaskInfo.Builder name(String name) {
            this.instance.name = name;
            return this;
        }

        public TaskInfo.Builder state(TaskState state) {
            this.instance.state = state;
            return this;
        }

        public TaskInfo.Builder currentProgressPercentage(Double currentProgressPercentage) {
            this.instance.currentProgressPercentage = currentProgressPercentage;
            return this;
        }

        public TaskInfo.Builder id(String id) {
            this.instance.id = id;
            return this;
        }

        public TaskInfo.Builder lastExecutionResult(TaskResult lastExecutionResult) {
            this.instance.lastExecutionResult = lastExecutionResult;
            return this;
        }

        public TaskInfo.Builder triggers(List<TaskTriggerInfo> triggers) {
            this.instance.triggers = triggers;
            return this;
        }

        public TaskInfo.Builder description(String description) {
            this.instance.description = description;
            return this;
        }

        public TaskInfo.Builder category(String category) {
            this.instance.category = category;
            return this;
        }

        public TaskInfo.Builder isHidden(Boolean isHidden) {
            this.instance.isHidden = isHidden;
            return this;
        }

        public TaskInfo.Builder key(String key) {
            this.instance.key = key;
            return this;
        }

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

    /**
     * Create a builder with a shallow copy of this instance.
     */
    public TaskInfo.Builder toBuilder() {
        return new TaskInfo.Builder().name(getName()).state(getState())
                .currentProgressPercentage(getCurrentProgressPercentage()).id(getId())
                .lastExecutionResult(getLastExecutionResult()).triggers(getTriggers()).description(getDescription())
                .category(getCategory()).isHidden(getIsHidden()).key(getKey());
    }
}
