// <auto-generated/>

#nullable disable

using System;
using System.ClientModel.Primitives;
using System.Collections.Generic;
using System.Xml;
using System.Xml.Linq;
using Sample.Models;

namespace Sample
{
    public partial class Model
    {
        protected 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.Model>)this).GetFormatFromOptions(options) : options.Format;
            if ((format != "X"))
            {
                throw new global::System.FormatException($"The model {nameof(global::Sample.Models.Model)} does not support writing '{format}' format.");
            }

            if (global::Sample.Optional.IsDefined(Prop2))
            {
                writer.WriteStartElement("prop1");
                writer.WriteValue(Prop2);
                writer.WriteEndElement();
            }
        }

        internal static global::Sample.Models.Model DeserializeModel(global::System.Xml.Linq.XElement element, global::System.ClientModel.Primitives.ModelReaderWriterOptions options)
        {
            if ((element == null))
            {
                return null;
            }

            string prop2 = default;
            global::System.Collections.Generic.IDictionary<string, global::System.BinaryData> additionalBinaryDataProperties = new global::Sample.ChangeTrackingDictionary<string, global::System.BinaryData>();

            foreach (var child in element.Elements())
            {
                string localName = child.Name.LocalName;
                if ((localName == "prop1"))
                {
                    prop2 = ((string)child);
                    continue;
                }
            }
            return new global::Sample.Models.Model(prop2, additionalBinaryDataProperties);
        }
    }
}
