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

package azure.clientgenerator.core.clientinitialization.defaultclient.models;

import com.azure.core.annotation.Generated;
import com.azure.core.annotation.Immutable;
import com.azure.core.util.CoreUtils;
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.OffsetDateTime;
import java.time.format.DateTimeFormatter;

/**
 * Properties of a blob.
 */
@Immutable
public final class BlobProperties implements JsonSerializable<BlobProperties> {
    /*
     * The name property.
     */
    @Generated
    private final String name;

    /*
     * The size property.
     */
    @Generated
    private final long size;

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

    /*
     * The createdOn property.
     */
    @Generated
    private final OffsetDateTime createdOn;

    /**
     * Creates an instance of BlobProperties class.
     * 
     * @param name the name value to set.
     * @param size the size value to set.
     * @param contentType the contentType value to set.
     * @param createdOn the createdOn value to set.
     */
    @Generated
    private BlobProperties(String name, long size, String contentType, OffsetDateTime createdOn) {
        this.name = name;
        this.size = size;
        this.contentType = contentType;
        this.createdOn = createdOn;
    }

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

    /**
     * Get the size property: The size property.
     * 
     * @return the size value.
     */
    @Generated
    public long getSize() {
        return this.size;
    }

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

    /**
     * Get the createdOn property: The createdOn property.
     * 
     * @return the createdOn value.
     */
    @Generated
    public OffsetDateTime getCreatedOn() {
        return this.createdOn;
    }

    /**
     * {@inheritDoc}
     */
    @Generated
    @Override
    public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
        jsonWriter.writeStartObject();
        jsonWriter.writeStringField("name", this.name);
        jsonWriter.writeLongField("size", this.size);
        jsonWriter.writeStringField("contentType", this.contentType);
        jsonWriter.writeStringField("createdOn",
            this.createdOn == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(this.createdOn));
        return jsonWriter.writeEndObject();
    }

    /**
     * Reads an instance of BlobProperties from the JsonReader.
     * 
     * @param jsonReader The JsonReader being read.
     * @return An instance of BlobProperties 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 BlobProperties.
     */
    @Generated
    public static BlobProperties fromJson(JsonReader jsonReader) throws IOException {
        return jsonReader.readObject(reader -> {
            String name = null;
            long size = 0L;
            String contentType = null;
            OffsetDateTime createdOn = null;
            while (reader.nextToken() != JsonToken.END_OBJECT) {
                String fieldName = reader.getFieldName();
                reader.nextToken();

                if ("name".equals(fieldName)) {
                    name = reader.getString();
                } else if ("size".equals(fieldName)) {
                    size = reader.getLong();
                } else if ("contentType".equals(fieldName)) {
                    contentType = reader.getString();
                } else if ("createdOn".equals(fieldName)) {
                    createdOn = reader
                        .getNullable(nonNullReader -> CoreUtils.parseBestOffsetDateTime(nonNullReader.getString()));
                } else {
                    reader.skipChildren();
                }
            }
            return new BlobProperties(name, size, contentType, createdOn);
        });
    }
}
