<filename>cadl-output/csharp/RegistrationResult.Serialization.cs<gh_stars>0// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

// <auto-generated/>

#nullable disable

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

namespace NotificationHubs.Models
{
    public partial class RegistrationResult : IUtf8JsonSerializable
    {
        void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
        {
            writer.WriteStartObject();
            writer.WritePropertyName("applicationPlatform");
            writer.WriteStringValue(ApplicationPlatform);
            writer.WritePropertyName("pnsHandle");
            writer.WriteStringValue(PnsHandle);
            writer.WritePropertyName("registrationId");
            writer.WriteStringValue(RegistrationId);
            writer.WritePropertyName("outcome");
            writer.WriteStringValue(Outcome);
            writer.WriteEndObject();
        }

        internal static RegistrationResult DeserializeRegistrationResult(JsonElement element)
        {
            string applicationPlatform = default;
            string pnsHandle = default;
            string registrationId = default;
            string outcome = default;
            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("applicationPlatform"))
                {
                    applicationPlatform = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("pnsHandle"))
                {
                    pnsHandle = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("registrationId"))
                {
                    registrationId = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("outcome"))
                {
                    outcome = property.Value.GetString();
                    continue;
                }
            }
            return new RegistrationResult(applicationPlatform, pnsHandle, registrationId, outcome);
        }

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

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