// <auto-generated/>

#nullable disable

using System;
using System.ClientModel.Primitives;
using System.IO;
using System.Xml;
using Sample.Models;

namespace Sample
{
    public partial class TestModel
    {
        protected virtual global::System.BinaryData PersistableModelWriteCore(global::System.ClientModel.Primitives.ModelReaderWriterOptions options)
        {
            string format = (options.Format == "W") ? ((global::System.ClientModel.Primitives.IPersistableModel<global::Sample.Models.TestModel>)this).GetFormatFromOptions(options) : options.Format;
            switch (format)
            {
                case "J":
                    return global::System.ClientModel.Primitives.ModelReaderWriter.Write(this, options, global::Sample.SampleContext.Default);
                case "X":
                    using (global::System.IO.MemoryStream stream = new global::System.IO.MemoryStream(256))
                    {
                        using (global::System.Xml.XmlWriter writer = global::System.Xml.XmlWriter.Create(stream, global::Sample.ModelSerializationExtensions.XmlWriterSettings))
                        {
                            this.WriteXml(writer, options, "TestModel");
                        }
                        if ((stream.Position > int.MaxValue))
                        {
                            return global::System.BinaryData.FromStream(stream);
                        }
                        else
                        {
                            return new global::System.BinaryData(stream.GetBuffer().AsMemory(0, ((int)stream.Position)));
                        }
                    }
                default:
                    throw new global::System.FormatException($"The model {nameof(global::Sample.Models.TestModel)} does not support writing '{options.Format}' format.");
            }
        }
    }
}
