// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

// <auto-generated/>

#nullable disable

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

namespace Azure.ResourceManager.AppService.Models
{
    public partial class HostName
    {
        internal static HostName DeserializeHostName(JsonElement element)
        {
            Optional<string> name = default;
            Optional<IReadOnlyList<string>> siteNames = default;
            Optional<string> azureResourceName = default;
            Optional<AzureResourceType> azureResourceType = default;
            Optional<CustomHostNameDnsRecordType> customHostNameDnsRecordType = default;
            Optional<HostNameType> hostNameType = default;
            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("name"))
                {
                    name = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("siteNames"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List<string> array = new List<string>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(item.GetString());
                    }
                    siteNames = array;
                    continue;
                }
                if (property.NameEquals("azureResourceName"))
                {
                    azureResourceName = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("azureResourceType"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    azureResourceType = property.Value.GetString().ToAzureResourceType();
                    continue;
                }
                if (property.NameEquals("customHostNameDnsRecordType"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    customHostNameDnsRecordType = property.Value.GetString().ToCustomHostNameDnsRecordType();
                    continue;
                }
                if (property.NameEquals("hostNameType"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    hostNameType = property.Value.GetString().ToHostNameType();
                    continue;
                }
            }
            return new HostName(name.Value, Optional.ToList(siteNames), azureResourceName.Value, Optional.ToNullable(azureResourceType), Optional.ToNullable(customHostNameDnsRecordType), Optional.ToNullable(hostNameType));
        }
    }
}
