// <auto-generated/>

#nullable disable

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

namespace Sample
{
    public partial class TestXmlModel
    {
        global::System.BinaryData global::System.ClientModel.Primitives.IPersistableModel<global::Sample.Models.TestXmlModel>.Write(global::System.ClientModel.Primitives.ModelReaderWriterOptions options) => this.PersistableModelWriteCore(options);

        private void WriteXml(global::System.Xml.XmlWriter writer, global::System.ClientModel.Primitives.ModelReaderWriterOptions options, string nameHint)
        {
            if ((nameHint != null))
            {
                writer.WriteStartElement(nameHint);
            }

            this.XmlModelWriteCore(writer, options);

            if ((nameHint != null))
            {
                writer.WriteEndElement();
            }
        }

        internal virtual void XmlModelWriteCore(global::System.Xml.XmlWriter writer, global::System.ClientModel.Primitives.ModelReaderWriterOptions options)
        {
            string format = (options.Format == "W") ? ((global::System.ClientModel.Primitives.IPersistableModel<global::Sample.Models.TestXmlModel>)this).GetFormatFromOptions(options) : options.Format;
            if ((format != "X"))
            {
                throw new global::System.FormatException($"The model {nameof(global::Sample.Models.TestXmlModel)} does not support writing '{format}' format.");
            }

            writer.WriteStartAttribute("id");
            writer.WriteValue(Id);
            writer.WriteEndAttribute();
            writer.WriteStartElement("name");
            writer.WriteValue(Name);
            writer.WriteEndElement();
        }
    }
}
