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

package client.naming.enumconflict.secondnamespace.models;

import com.azure.core.annotation.Generated;
import com.azure.core.annotation.Immutable;
import com.azure.json.JsonReader;
import com.azure.json.JsonSerializable;
import com.azure.json.JsonToken;
import com.azure.json.JsonWriter;
import java.io.IOException;

/**
 * The SecondModel model.
 */
@Immutable
public final class SecondModel implements JsonSerializable<SecondModel> {
    /*
     * Status from second namespace
     */
    @Generated
    private final SecondStatus status;

    /*
     * Description of the item
     */
    @Generated
    private final String description;

    /**
     * Creates an instance of SecondModel class.
     * 
     * @param status the status value to set.
     * @param description the description value to set.
     */
    @Generated
    public SecondModel(SecondStatus status, String description) {
        this.status = status;
        this.description = description;
    }

    /**
     * Get the status property: Status from second namespace.
     * 
     * @return the status value.
     */
    @Generated
    public SecondStatus getStatus() {
        return this.status;
    }

    /**
     * Get the description property: Description of the item.
     * 
     * @return the description value.
     */
    @Generated
    public String getDescription() {
        return this.description;
    }

    /**
     * {@inheritDoc}
     */
    @Generated
    @Override
    public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
        jsonWriter.writeStartObject();
        jsonWriter.writeStringField("status", this.status == null ? null : this.status.toString());
        jsonWriter.writeStringField("description", this.description);
        return jsonWriter.writeEndObject();
    }

    /**
     * Reads an instance of SecondModel from the JsonReader.
     * 
     * @param jsonReader The JsonReader being read.
     * @return An instance of SecondModel 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 SecondModel.
     */
    @Generated
    public static SecondModel fromJson(JsonReader jsonReader) throws IOException {
        return jsonReader.readObject(reader -> {
            SecondStatus status = null;
            String description = null;
            while (reader.nextToken() != JsonToken.END_OBJECT) {
                String fieldName = reader.getFieldName();
                reader.nextToken();

                if ("status".equals(fieldName)) {
                    status = SecondStatus.fromString(reader.getString());
                } else if ("description".equals(fieldName)) {
                    description = reader.getString();
                } else {
                    reader.skipChildren();
                }
            }
            return new SecondModel(status, description);
        });
    }
}
