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

namespace Azure.ResourceManager.Resources.Models
{
    public partial class TemplateSpecVersionInfo
    {
        internal static TemplateSpecVersionInfo DeserializeTemplateSpecVersionInfo(JsonElement element)
        {
            Optional<string> description = default;
            Optional<DateTimeOffset> timeCreated = default;
            Optional<DateTimeOffset> timeModified = default;
            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("description"))
                {
                    description = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("timeCreated"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    timeCreated = property.Value.GetDateTimeOffset("O");
                    continue;
                }
                if (property.NameEquals("timeModified"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    timeModified = property.Value.GetDateTimeOffset("O");
                    continue;
                }
            }
            return new TemplateSpecVersionInfo(description.Value, Optional.ToNullable(timeCreated), Optional.ToNullable(timeModified));
        }
    }
}
