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

package tsptest.external.models;

import com.azure.core.annotation.Fluent;
import com.azure.core.annotation.Generated;
import com.azure.core.models.CloudEventDataFormat;
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 java.time.DayOfWeek;

/**
 * The Body model.
 */
@Fluent
public final class Body implements JsonSerializable<Body> {
    /*
     * The cloudEventDataFormat property.
     */
    @Generated
    private CloudEventDataFormat cloudEventDataFormat;

    /*
     * The dayOfWeek property.
     */
    @Generated
    private DayOfWeek dayOfWeek;

    /**
     * Creates an instance of Body class.
     */
    @Generated
    public Body() {
    }

    /**
     * Get the cloudEventDataFormat property: The cloudEventDataFormat property.
     * 
     * @return the cloudEventDataFormat value.
     */
    @Generated
    public CloudEventDataFormat getCloudEventDataFormat() {
        return this.cloudEventDataFormat;
    }

    /**
     * Set the cloudEventDataFormat property: The cloudEventDataFormat property.
     * 
     * @param cloudEventDataFormat the cloudEventDataFormat value to set.
     * @return the Body object itself.
     */
    @Generated
    public Body setCloudEventDataFormat(CloudEventDataFormat cloudEventDataFormat) {
        this.cloudEventDataFormat = cloudEventDataFormat;
        return this;
    }

    /**
     * Get the dayOfWeek property: The dayOfWeek property.
     * 
     * @return the dayOfWeek value.
     */
    @Generated
    public DayOfWeek getDayOfWeek() {
        return this.dayOfWeek;
    }

    /**
     * Set the dayOfWeek property: The dayOfWeek property.
     * 
     * @param dayOfWeek the dayOfWeek value to set.
     * @return the Body object itself.
     */
    @Generated
    public Body setDayOfWeek(DayOfWeek dayOfWeek) {
        this.dayOfWeek = dayOfWeek;
        return this;
    }

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

    /**
     * Reads an instance of Body from the JsonReader.
     * 
     * @param jsonReader The JsonReader being read.
     * @return An instance of Body if the JsonReader was pointing to an instance of it, or null if it was pointing to
     * JSON null.
     * @throws IOException If an error occurs while reading the Body.
     */
    @Generated
    public static Body fromJson(JsonReader jsonReader) throws IOException {
        return jsonReader.readObject(reader -> {
            Body deserializedBody = new Body();
            while (reader.nextToken() != JsonToken.END_OBJECT) {
                String fieldName = reader.getFieldName();
                reader.nextToken();

                if ("cloudEventDataFormat".equals(fieldName)) {
                    deserializedBody.cloudEventDataFormat = CloudEventDataFormat.fromString(reader.getString());
                } else if ("dayOfWeek".equals(fieldName)) {
                    deserializedBody.dayOfWeek = DayOfWeek.valueOf(reader.getString());
                } else {
                    reader.skipChildren();
                }
            }

            return deserializedBody;
        });
    }
}
