// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) TypeSpec Code Generator.

package tsptest.flatten.implementation.models;

import com.azure.core.annotation.Fluent;
import com.azure.core.annotation.Generated;
import com.azure.json.JsonReader;
import com.azure.json.JsonSerializable;
import com.azure.json.JsonToken;
import com.azure.json.JsonWriter;
import java.io.IOException;
import tsptest.flatten.models.User;

/**
 * The SendRequest model.
 */
@Fluent
public final class SendRequest implements JsonSerializable<SendRequest> {
    /*
     * The endpoint property.
     */
    @Generated
    private final String endpoint;

    /*
     * The user property.
     */
    @Generated
    private User user;

    /*
     * The input property.
     */
    @Generated
    private final String input;

    /*
     * The constant property.
     */
    @Generated
    private final String constant = "constant";

    /*
     * The requiredInt property.
     */
    @Generated
    private final int requiredInt;

    /**
     * Creates an instance of SendRequest class.
     * 
     * @param endpoint the endpoint value to set.
     * @param input the input value to set.
     * @param requiredInt the requiredInt value to set.
     */
    @Generated
    public SendRequest(String endpoint, String input, int requiredInt) {
        this.endpoint = endpoint;
        this.input = input;
        this.requiredInt = requiredInt;
    }

    /**
     * Get the endpoint property: The endpoint property.
     * 
     * @return the endpoint value.
     */
    @Generated
    public String getEndpoint() {
        return this.endpoint;
    }

    /**
     * Get the user property: The user property.
     * 
     * @return the user value.
     */
    @Generated
    public User getUser() {
        return this.user;
    }

    /**
     * Set the user property: The user property.
     * 
     * @param user the user value to set.
     * @return the SendRequest object itself.
     */
    @Generated
    public SendRequest setUser(User user) {
        this.user = user;
        return this;
    }

    /**
     * Get the input property: The input property.
     * 
     * @return the input value.
     */
    @Generated
    public String getInput() {
        return this.input;
    }

    /**
     * Get the constant property: The constant property.
     * 
     * @return the constant value.
     */
    @Generated
    public String getConstant() {
        return this.constant;
    }

    /**
     * Get the requiredInt property: The requiredInt property.
     * 
     * @return the requiredInt value.
     */
    @Generated
    public int getRequiredInt() {
        return this.requiredInt;
    }

    /**
     * {@inheritDoc}
     */
    @Generated
    @Override
    public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
        jsonWriter.writeStartObject();
        jsonWriter.writeStringField("endpoint", this.endpoint);
        jsonWriter.writeStringField("input", this.input);
        jsonWriter.writeStringField("constant", this.constant);
        jsonWriter.writeIntField("requiredInt", this.requiredInt);
        jsonWriter.writeJsonField("user", this.user);
        return jsonWriter.writeEndObject();
    }

    /**
     * Reads an instance of SendRequest from the JsonReader.
     * 
     * @param jsonReader The JsonReader being read.
     * @return An instance of SendRequest if the JsonReader was pointing to an instance of it, or null if it was
     * pointing to JSON null.
     * @throws IllegalStateException If the deserialized JSON object was missing any required properties.
     * @throws IOException If an error occurs while reading the SendRequest.
     */
    @Generated
    public static SendRequest fromJson(JsonReader jsonReader) throws IOException {
        return jsonReader.readObject(reader -> {
            String endpoint = null;
            String input = null;
            int requiredInt = 0;
            User user = null;
            while (reader.nextToken() != JsonToken.END_OBJECT) {
                String fieldName = reader.getFieldName();
                reader.nextToken();

                if ("endpoint".equals(fieldName)) {
                    endpoint = reader.getString();
                } else if ("input".equals(fieldName)) {
                    input = reader.getString();
                } else if ("requiredInt".equals(fieldName)) {
                    requiredInt = reader.getInt();
                } else if ("user".equals(fieldName)) {
                    user = User.fromJson(reader);
                } else {
                    reader.skipChildren();
                }
            }
            SendRequest deserializedSendRequest = new SendRequest(endpoint, input, requiredInt);
            deserializedSendRequest.user = user;

            return deserializedSendRequest;
        });
    }
}
