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

/**
 * Query result container.
 */
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "OpenAPI Generator")
public class AuthenticationInfoQueryResult {
    public static final String JSON_PROPERTY_ITEMS = "Items";
    private @org.eclipse.jdt.annotation.Nullable List<AuthenticationInfo> items = new ArrayList<>();

    public static final String JSON_PROPERTY_TOTAL_RECORD_COUNT = "TotalRecordCount";
    private @org.eclipse.jdt.annotation.Nullable Integer totalRecordCount;

    public static final String JSON_PROPERTY_START_INDEX = "StartIndex";
    private @org.eclipse.jdt.annotation.Nullable Integer startIndex;

    public AuthenticationInfoQueryResult() {
    }

    public AuthenticationInfoQueryResult items(@org.eclipse.jdt.annotation.Nullable List<AuthenticationInfo> items) {
        this.items = items;
        return this;
    }

    public AuthenticationInfoQueryResult addItemsItem(AuthenticationInfo itemsItem) {
        if (this.items == null) {
            this.items = new ArrayList<>();
        }
        this.items.add(itemsItem);
        return this;
    }

    /**
     * Gets or sets the items.
     * 
     * @return items
     */
    @JsonProperty(value = JSON_PROPERTY_ITEMS)
    public @org.eclipse.jdt.annotation.Nullable List<AuthenticationInfo> getItems() {
        return items;
    }

    @JsonProperty(value = JSON_PROPERTY_ITEMS)
    public void setItems(@org.eclipse.jdt.annotation.Nullable List<AuthenticationInfo> items) {
        this.items = items;
    }

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

    /**
     * Gets or sets the total number of records available.
     * 
     * @return totalRecordCount
     */
    @JsonProperty(value = JSON_PROPERTY_TOTAL_RECORD_COUNT)
    public @org.eclipse.jdt.annotation.Nullable Integer getTotalRecordCount() {
        return totalRecordCount;
    }

    @JsonProperty(value = JSON_PROPERTY_TOTAL_RECORD_COUNT)
    public void setTotalRecordCount(@org.eclipse.jdt.annotation.Nullable Integer totalRecordCount) {
        this.totalRecordCount = totalRecordCount;
    }

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

    /**
     * Gets or sets the index of the first record in Items.
     * 
     * @return startIndex
     */
    @JsonProperty(value = JSON_PROPERTY_START_INDEX)
    public @org.eclipse.jdt.annotation.Nullable Integer getStartIndex() {
        return startIndex;
    }

    @JsonProperty(value = JSON_PROPERTY_START_INDEX)
    public void setStartIndex(@org.eclipse.jdt.annotation.Nullable Integer startIndex) {
        this.startIndex = startIndex;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        AuthenticationInfoQueryResult authenticationInfoQueryResult = (AuthenticationInfoQueryResult) o;
        return Objects.equals(this.items, authenticationInfoQueryResult.items)
                && Objects.equals(this.totalRecordCount, authenticationInfoQueryResult.totalRecordCount)
                && Objects.equals(this.startIndex, authenticationInfoQueryResult.startIndex);
    }

    @Override
    public int hashCode() {
        return Objects.hash(items, totalRecordCount, startIndex);
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("class AuthenticationInfoQueryResult {\n");
        sb.append("    items: ").append(toIndentedString(items)).append("\n");
        sb.append("    totalRecordCount: ").append(toIndentedString(totalRecordCount)).append("\n");
        sb.append("    startIndex: ").append(toIndentedString(startIndex)).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 `Items` to the URL query string
        if (getItems() != null) {
            for (int i = 0; i < getItems().size(); i++) {
                if (getItems().get(i) != null) {
                    joiner.add(getItems().get(i)
                            .toUrlQueryString(String.format(java.util.Locale.ROOT, "%sItems%s%s", prefix, suffix,
                                    "".equals(suffix) ? ""
                                            : String.format(java.util.Locale.ROOT, "%s%d%s", containerPrefix, i,
                                                    containerSuffix))));
                }
            }
        }

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

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

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

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

        public AuthenticationInfoQueryResult.Builder items(List<AuthenticationInfo> items) {
            this.instance.items = items;
            return this;
        }

        public AuthenticationInfoQueryResult.Builder totalRecordCount(Integer totalRecordCount) {
            this.instance.totalRecordCount = totalRecordCount;
            return this;
        }

        public AuthenticationInfoQueryResult.Builder startIndex(Integer startIndex) {
            this.instance.startIndex = startIndex;
            return this;
        }

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

    /**
     * Create a builder with a shallow copy of this instance.
     */
    public AuthenticationInfoQueryResult.Builder toBuilder() {
        return new AuthenticationInfoQueryResult.Builder().items(getItems()).totalRecordCount(getTotalRecordCount())
                .startIndex(getStartIndex());
    }
}
