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

package azure.resourcemanager.resources.models;

import com.azure.core.annotation.Fluent;
import com.azure.core.util.logging.ClientLogger;
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 details of a user notification.
 */
@Fluent
public final class NotificationDetails implements JsonSerializable<NotificationDetails> {
    /*
     * The notification message.
     */
    private String message;

    /*
     * If true, the notification is urgent.
     */
    private boolean urgent;

    /**
     * Creates an instance of NotificationDetails class.
     */
    public NotificationDetails() {
    }

    /**
     * Get the message property: The notification message.
     * 
     * @return the message value.
     */
    public String message() {
        return this.message;
    }

    /**
     * Set the message property: The notification message.
     * 
     * @param message the message value to set.
     * @return the NotificationDetails object itself.
     */
    public NotificationDetails withMessage(String message) {
        this.message = message;
        return this;
    }

    /**
     * Get the urgent property: If true, the notification is urgent.
     * 
     * @return the urgent value.
     */
    public boolean urgent() {
        return this.urgent;
    }

    /**
     * Set the urgent property: If true, the notification is urgent.
     * 
     * @param urgent the urgent value to set.
     * @return the NotificationDetails object itself.
     */
    public NotificationDetails withUrgent(boolean urgent) {
        this.urgent = urgent;
        return this;
    }

    /**
     * Validates the instance.
     * 
     * @throws IllegalArgumentException thrown if the instance is not valid.
     */
    public void validate() {
        if (message() == null) {
            throw LOGGER.atError()
                .log(new IllegalArgumentException("Missing required property message in model NotificationDetails"));
        }
    }

    private static final ClientLogger LOGGER = new ClientLogger(NotificationDetails.class);

    /**
     * {@inheritDoc}
     */
    @Override
    public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
        jsonWriter.writeStartObject();
        jsonWriter.writeStringField("message", this.message);
        jsonWriter.writeBooleanField("urgent", this.urgent);
        return jsonWriter.writeEndObject();
    }

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

                if ("message".equals(fieldName)) {
                    deserializedNotificationDetails.message = reader.getString();
                } else if ("urgent".equals(fieldName)) {
                    deserializedNotificationDetails.urgent = reader.getBoolean();
                } else {
                    reader.skipChildren();
                }
            }

            return deserializedNotificationDetails;
        });
    }
}
