using System.Text.Json;
using Azure.Core;

namespace Azure.ResourceManager.AppContainers.Models
{
    internal partial class ManagedEnvironmentStorageProperties : IUtf8JsonSerializable
    {
        void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
        {
            writer.WriteStartObject();
            if (Optional.IsDefined(AzureFile))
            {
                writer.WritePropertyName("azureFile");
                writer.WriteObjectValue(AzureFile);
            }
            writer.WriteEndObject();
        }

        internal static ManagedEnvironmentStorageProperties DeserializeManagedEnvironmentStorageProperties(JsonElement element)
        {
            Optional<AzureFileProperties> azureFile = default;
            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("azureFile"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    azureFile = AzureFileProperties.DeserializeAzureFileProperties(property.Value);
                    continue;
                }
            }
            return new ManagedEnvironmentStorageProperties(azureFile.Value);
        }
    }
}
