internal static ServicePrincipalListResult DeserializeServicePrincipalListResult(JsonElement element)
        {
            Optional <IReadOnlyList <ServicePrincipal> > value = default;
            Optional <string> odataNextLink = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("value"))
                {
                    List <ServicePrincipal> array = new List <ServicePrincipal>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(ServicePrincipal.DeserializeServicePrincipal(item));
                    }
                    value = array;
                    continue;
                }
                if (property.NameEquals("odata.nextLink"))
                {
                    odataNextLink = property.Value.GetString();
                    continue;
                }
            }
            return(new ServicePrincipalListResult(Optional.ToList(value), odataNextLink.Value));
        }
        internal static DirectoryObject DeserializeDirectoryObject(JsonElement element)
        {
            if (element.TryGetProperty("objectType", out JsonElement discriminator))
            {
                switch (discriminator.GetString())
                {
                case "AppRoleAssignment": return(AppRoleAssignment.DeserializeAppRoleAssignment(element));

                case "Application": return(Application.DeserializeApplication(element));

                case "Group": return(ADGroup.DeserializeADGroup(element));

                case "ServicePrincipal": return(ServicePrincipal.DeserializeServicePrincipal(element));

                case "User": return(User.DeserializeUser(element));
                }
            }
            Optional <string>                    objectId                       = default;
            string                               objectType                     = default;
            Optional <DateTimeOffset?>           deletionTimestamp              = default;
            IReadOnlyDictionary <string, object> additionalProperties           = default;
            Dictionary <string, object>          additionalPropertiesDictionary = new Dictionary <string, object>();

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("objectId"))
                {
                    objectId = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("objectType"))
                {
                    objectType = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("deletionTimestamp"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        deletionTimestamp = null;
                        continue;
                    }
                    deletionTimestamp = property.Value.GetDateTimeOffset("O");
                    continue;
                }
                additionalPropertiesDictionary.Add(property.Name, property.Value.GetObject());
            }
            additionalProperties = additionalPropertiesDictionary;
            return(new DirectoryObject(objectId.Value, objectType, Optional.ToNullable(deletionTimestamp), additionalProperties));
        }
        internal static ServicePrincipalListResult DeserializeServicePrincipalListResult(JsonElement element)
        {
            IReadOnlyList <ServicePrincipal> value = default;
            string odataNextLink = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("value"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    List <ServicePrincipal> array = new List <ServicePrincipal>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        if (item.ValueKind == JsonValueKind.Null)
                        {
                            array.Add(null);
                        }
                        else
                        {
                            array.Add(ServicePrincipal.DeserializeServicePrincipal(item));
                        }
                    }
                    value = array;
                    continue;
                }
                if (property.NameEquals("odata.nextLink"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    odataNextLink = property.Value.GetString();
                    continue;
                }
            }
            return(new ServicePrincipalListResult(value, odataNextLink));
        }