// <auto-generated/>

#nullable disable

using System;
using System.ClientModel.Primitives;
using System.IO;
using System.Xml.Linq;

namespace Sample.Models
{
    public partial class OuterModel : global::System.ClientModel.Primitives.IPersistableModel<global::Sample.Models.OuterModel>
    {
        protected virtual global::Sample.Models.OuterModel PersistableModelCreateCore(global::System.BinaryData data, global::System.ClientModel.Primitives.ModelReaderWriterOptions options)
        {
            string format = (options.Format == "W") ? ((global::System.ClientModel.Primitives.IPersistableModel<global::Sample.Models.OuterModel>)this).GetFormatFromOptions(options) : options.Format;
            switch (format)
            {
                case "X":
                    using (global::System.IO.Stream dataStream = data.ToStream())
                    {
                        return global::Sample.Models.OuterModel.DeserializeOuterModel(global::System.Xml.Linq.XElement.Load(dataStream, global::System.Xml.Linq.LoadOptions.PreserveWhitespace), options);
                    }
                default:
                    throw new global::System.FormatException($"The model {nameof(global::Sample.Models.OuterModel)} does not support reading '{options.Format}' format.");
            }
        }

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

            global::Sample.Models.InnerModel inner = default;

            foreach (var child in element.Elements())
            {
                string localName = child.Name.LocalName;
                if ((localName == "inner"))
                {
                    inner = global::Sample.Models.InnerModel.DeserializeInnerModel(child, options);
                    continue;
                }
            }
            return new global::Sample.Models.OuterModel(inner);
        }
    }
}
