<gh_stars>0// 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;
using Azure.Core;

namespace NotificationHubs.Models
{
    public partial class NotificationOutcome : IUtf8JsonSerializable
    {
        void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
        {
            writer.WriteStartObject();
            writer.WritePropertyName("success");
            writer.WriteNumberValue(Success);
            writer.WritePropertyName("failure");
            writer.WriteNumberValue(Failure);
            writer.WritePropertyName("results");
            writer.WriteStartArray();
            foreach (var item in Results)
            {
                writer.WriteObjectValue(item);
            }
            writer.WriteEndArray();
            writer.WriteEndObject();
        }

        internal static NotificationOutcome DeserializeNotificationOutcome(JsonElement element)
        {
            int success = default;
            int failure = default;
            IList<RegistrationResult> results = default;
            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("success"))
                {
                    success = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("failure"))
                {
                    failure = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("results"))
                {
                    List<RegistrationResult> array = new List<RegistrationResult>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(RegistrationResult.DeserializeRegistrationResult(item));
                    }
                    results = array;
                    continue;
                }
            }
            return new NotificationOutcome(success, failure, results);
        }

        internal RequestContent ToRequestContent()
        {
            var content = new Utf8JsonRequestContent();
            content.JsonWriter.WriteObjectValue(this);
            return content;
        }

        internal static NotificationOutcome FromResponse(Response response)
        {
            using var document = JsonDocument.Parse(response.Content);
            return DeserializeNotificationOutcome(document.RootElement);
        }
    }
}
