/*
 * 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 java.util.UUID;

import com.fasterxml.jackson.annotation.JsonProperty;

/**
 * Class PlayRequestDto.
 */
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "OpenAPI Generator")
public class PlayRequestDto {
    public static final String JSON_PROPERTY_PLAYING_QUEUE = "PlayingQueue";
    private @org.eclipse.jdt.annotation.Nullable List<UUID> playingQueue = new ArrayList<>();

    public static final String JSON_PROPERTY_PLAYING_ITEM_POSITION = "PlayingItemPosition";
    private @org.eclipse.jdt.annotation.Nullable Integer playingItemPosition;

    public static final String JSON_PROPERTY_START_POSITION_TICKS = "StartPositionTicks";
    private @org.eclipse.jdt.annotation.Nullable Long startPositionTicks;

    public PlayRequestDto() {
    }

    public PlayRequestDto playingQueue(@org.eclipse.jdt.annotation.Nullable List<UUID> playingQueue) {
        this.playingQueue = playingQueue;
        return this;
    }

    public PlayRequestDto addPlayingQueueItem(UUID playingQueueItem) {
        if (this.playingQueue == null) {
            this.playingQueue = new ArrayList<>();
        }
        this.playingQueue.add(playingQueueItem);
        return this;
    }

    /**
     * Gets or sets the playing queue.
     * 
     * @return playingQueue
     */
    @JsonProperty(value = JSON_PROPERTY_PLAYING_QUEUE)
    public @org.eclipse.jdt.annotation.Nullable List<UUID> getPlayingQueue() {
        return playingQueue;
    }

    @JsonProperty(value = JSON_PROPERTY_PLAYING_QUEUE)
    public void setPlayingQueue(@org.eclipse.jdt.annotation.Nullable List<UUID> playingQueue) {
        this.playingQueue = playingQueue;
    }

    public PlayRequestDto playingItemPosition(@org.eclipse.jdt.annotation.Nullable Integer playingItemPosition) {
        this.playingItemPosition = playingItemPosition;
        return this;
    }

    /**
     * Gets or sets the position of the playing item in the queue.
     * 
     * @return playingItemPosition
     */
    @JsonProperty(value = JSON_PROPERTY_PLAYING_ITEM_POSITION)
    public @org.eclipse.jdt.annotation.Nullable Integer getPlayingItemPosition() {
        return playingItemPosition;
    }

    @JsonProperty(value = JSON_PROPERTY_PLAYING_ITEM_POSITION)
    public void setPlayingItemPosition(@org.eclipse.jdt.annotation.Nullable Integer playingItemPosition) {
        this.playingItemPosition = playingItemPosition;
    }

    public PlayRequestDto startPositionTicks(@org.eclipse.jdt.annotation.Nullable Long startPositionTicks) {
        this.startPositionTicks = startPositionTicks;
        return this;
    }

    /**
     * Gets or sets the start position ticks.
     * 
     * @return startPositionTicks
     */
    @JsonProperty(value = JSON_PROPERTY_START_POSITION_TICKS)
    public @org.eclipse.jdt.annotation.Nullable Long getStartPositionTicks() {
        return startPositionTicks;
    }

    @JsonProperty(value = JSON_PROPERTY_START_POSITION_TICKS)
    public void setStartPositionTicks(@org.eclipse.jdt.annotation.Nullable Long startPositionTicks) {
        this.startPositionTicks = startPositionTicks;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        PlayRequestDto playRequestDto = (PlayRequestDto) o;
        return Objects.equals(this.playingQueue, playRequestDto.playingQueue)
                && Objects.equals(this.playingItemPosition, playRequestDto.playingItemPosition)
                && Objects.equals(this.startPositionTicks, playRequestDto.startPositionTicks);
    }

    @Override
    public int hashCode() {
        return Objects.hash(playingQueue, playingItemPosition, startPositionTicks);
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("class PlayRequestDto {\n");
        sb.append("    playingQueue: ").append(toIndentedString(playingQueue)).append("\n");
        sb.append("    playingItemPosition: ").append(toIndentedString(playingItemPosition)).append("\n");
        sb.append("    startPositionTicks: ").append(toIndentedString(startPositionTicks)).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 `PlayingQueue` to the URL query string
        if (getPlayingQueue() != null) {
            for (int i = 0; i < getPlayingQueue().size(); i++) {
                if (getPlayingQueue().get(i) != null) {
                    try {
                        joiner.add(String.format(java.util.Locale.ROOT, "%sPlayingQueue%s%s=%s", prefix, suffix,
                                "".equals(suffix) ? ""
                                        : String.format(java.util.Locale.ROOT, "%s%d%s", containerPrefix, i,
                                                containerSuffix),
                                URLEncoder.encode(String.valueOf(getPlayingQueue().get(i)), "UTF-8").replaceAll("\\+",
                                        "%20")));
                    } catch (UnsupportedEncodingException e) {
                        // Should never happen, UTF-8 is always supported
                        throw new RuntimeException(e);
                    }
                }
            }
        }

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

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

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

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

        public PlayRequestDto.Builder playingQueue(List<UUID> playingQueue) {
            this.instance.playingQueue = playingQueue;
            return this;
        }

        public PlayRequestDto.Builder playingItemPosition(Integer playingItemPosition) {
            this.instance.playingItemPosition = playingItemPosition;
            return this;
        }

        public PlayRequestDto.Builder startPositionTicks(Long startPositionTicks) {
            this.instance.startPositionTicks = startPositionTicks;
            return this;
        }

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

    /**
     * Create a builder with a shallow copy of this instance.
     */
    public PlayRequestDto.Builder toBuilder() {
        return new PlayRequestDto.Builder().playingQueue(getPlayingQueue())
                .playingItemPosition(getPlayingItemPosition()).startPositionTicks(getStartPositionTicks());
    }
}
