// <auto-generated/>

#nullable disable

using System;
using System.ClientModel;
using System.ClientModel.Primitives;
using System.IO;
using System.Text.Json;
using System.Xml.Linq;
using Sample.Models;

namespace Sample
{
    public partial class TestModel
    {
        public static explicit operator TestModel(global::System.ClientModel.ClientResult result)
        {
            using global::System.ClientModel.Primitives.PipelineResponse response = result.GetRawResponse();

            if ((response.Headers.TryGetValue("Content-Type", out string value) && value.StartsWith("application/json", global::System.StringComparison.OrdinalIgnoreCase)))
            {
                using global::System.Text.Json.JsonDocument document = global::System.Text.Json.JsonDocument.Parse(response.Content, global::Sample.ModelSerializationExtensions.JsonDocumentOptions);
                return global::Sample.Models.TestModel.DeserializeTestModel(document.RootElement, global::Sample.ModelSerializationExtensions.WireOptions);
            }

            using global::System.IO.Stream stream = response.ContentStream;
            if ((stream == null))
            {
                return default;
            }

            return global::Sample.Models.TestModel.DeserializeTestModel(global::System.Xml.Linq.XElement.Load(stream, global::System.Xml.Linq.LoadOptions.PreserveWhitespace), global::Sample.ModelSerializationExtensions.WireOptions);
        }
    }
}
