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

/**
 * Class GroupStateUpdate.
 */
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "OpenAPI Generator")
public class GroupStateUpdate {
    public static final String JSON_PROPERTY_STATE = "State";
    private @org.eclipse.jdt.annotation.Nullable GroupStateType state;

    public static final String JSON_PROPERTY_REASON = "Reason";
    private @org.eclipse.jdt.annotation.Nullable PlaybackRequestType reason;

    public GroupStateUpdate() {
    }

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

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

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

    public GroupStateUpdate reason(@org.eclipse.jdt.annotation.Nullable PlaybackRequestType reason) {
        this.reason = reason;
        return this;
    }

    /**
     * Gets the reason of the state change.
     * 
     * @return reason
     */
    @JsonProperty(value = JSON_PROPERTY_REASON)
    public @org.eclipse.jdt.annotation.Nullable PlaybackRequestType getReason() {
        return reason;
    }

    @JsonProperty(value = JSON_PROPERTY_REASON)
    public void setReason(@org.eclipse.jdt.annotation.Nullable PlaybackRequestType reason) {
        this.reason = reason;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        GroupStateUpdate groupStateUpdate = (GroupStateUpdate) o;
        return Objects.equals(this.state, groupStateUpdate.state)
                && Objects.equals(this.reason, groupStateUpdate.reason);
    }

    @Override
    public int hashCode() {
        return Objects.hash(state, reason);
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("class GroupStateUpdate {\n");
        sb.append("    state: ").append(toIndentedString(state)).append("\n");
        sb.append("    reason: ").append(toIndentedString(reason)).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 `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 `Reason` to the URL query string
        if (getReason() != null) {
            try {
                joiner.add(String.format(java.util.Locale.ROOT, "%sReason%s=%s", prefix, suffix,
                        URLEncoder.encode(String.valueOf(getReason()), "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 GroupStateUpdate instance;

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

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

        public GroupStateUpdate.Builder state(GroupStateType state) {
            this.instance.state = state;
            return this;
        }

        public GroupStateUpdate.Builder reason(PlaybackRequestType reason) {
            this.instance.reason = reason;
            return this;
        }

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

    /**
     * Create a builder with a shallow copy of this instance.
     */
    public GroupStateUpdate.Builder toBuilder() {
        return new GroupStateUpdate.Builder().state(getState()).reason(getReason());
    }
}
