/* DO NOT EDIT */
/* This file was generated from auth.stone */

package com.dropbox.core.v2.auth;

import com.dropbox.core.stone.StoneDeserializerLogger;
import com.dropbox.core.stone.StoneSerializers;
import com.dropbox.core.stone.StructSerializer;

import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;

import java.io.IOException;
import java.util.Arrays;

public class TokenScopeError {
    // struct auth.TokenScopeError (auth.stone)

    protected final String requiredScope;

    /**
     *
     * @param requiredScope  The required scope to access the route. Must not be
     *     {@code null}.
     *
     * @throws IllegalArgumentException  If any argument does not meet its
     *     preconditions.
     */
    public TokenScopeError(String requiredScope) {
        if (requiredScope == null) {
            throw new IllegalArgumentException("Required value for 'requiredScope' is null");
        }
        this.requiredScope = requiredScope;
    }

    /**
     * The required scope to access the route.
     *
     * @return value for this field, never {@code null}.
     */
    public String getRequiredScope() {
        return requiredScope;
    }

    @Override
    public int hashCode() {
        int hash = Arrays.hashCode(new Object [] {
            requiredScope
        });
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == this) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        // be careful with inheritance
        else if (obj.getClass().equals(this.getClass())) {
            TokenScopeError other = (TokenScopeError) obj;
            return (this.requiredScope == other.requiredScope) || (this.requiredScope.equals(other.requiredScope));
        }
        else {
            return false;
        }
    }

    @Override
    public String toString() {
        return Serializer.INSTANCE.serialize(this, false);
    }

    /**
     * Returns a String representation of this object formatted for easier
     * readability.
     *
     * <p> The returned String may contain newlines. </p>
     *
     * @return Formatted, multiline String representation of this object
     */
    public String toStringMultiline() {
        return Serializer.INSTANCE.serialize(this, true);
    }

    /**
     * For internal use only.
     */
    public static class Serializer extends StructSerializer<TokenScopeError> {
        public static final Serializer INSTANCE = new Serializer();

        @Override
        public void serialize(TokenScopeError value, JsonGenerator g, boolean collapse) throws IOException, JsonGenerationException {
            if (!collapse) {
                g.writeStartObject();
            }
            g.writeFieldName("required_scope");
            StoneSerializers.string().serialize(value.requiredScope, g);
            if (!collapse) {
                g.writeEndObject();
            }
        }

        @Override
        public TokenScopeError deserialize(JsonParser p, boolean collapsed) throws IOException, JsonParseException {
            TokenScopeError value;
            String tag = null;
            if (!collapsed) {
                expectStartObject(p);
                tag = readTag(p);
            }
            if (tag == null) {
                String f_requiredScope = null;
                while (p.getCurrentToken() == JsonToken.FIELD_NAME) {
                    String field = p.getCurrentName();
                    p.nextToken();
                    if ("required_scope".equals(field)) {
                        f_requiredScope = StoneSerializers.string().deserialize(p);
                    }
                    else {
                        skipValue(p);
                    }
                }
                if (f_requiredScope == null) {
                    throw new JsonParseException(p, "Required field \"required_scope\" missing.");
                }
                value = new TokenScopeError(f_requiredScope);
            }
            else {
                throw new JsonParseException(p, "No subtype found that matches tag: \"" + tag + "\"");
            }
            if (!collapsed) {
                expectEndObject(p);
            }
            StoneDeserializerLogger.log(value, value.toStringMultiline());
            return value;
        }
    }
}
