// <auto-generated/>

#nullable disable

using System;
using System.ClientModel.Primitives;
using System.Collections.Generic;
using System.Text;
using System.Text.Json;
using Sample.Models;

namespace Sample
{
    public partial class DynamicModel
    {
        internal static global::Sample.Models.DynamicModel DeserializeDynamicModel(global::System.Text.Json.JsonElement element, global::System.BinaryData data, global::System.ClientModel.Primitives.ModelReaderWriterOptions options)
        {
            if ((element.ValueKind == global::System.Text.Json.JsonValueKind.Null))
            {
                return null;
            }
            global::System.Collections.Generic.IList<global::Sample.Models.Cat> cats = default;
            global::System.Collections.Generic.IList<string> names = default;
            global::System.Collections.Generic.IList<string> optionalNames = default;
#pragma warning disable SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates.
            global::System.ClientModel.Primitives.JsonPatch patch = new global::System.ClientModel.Primitives.JsonPatch((data is null) ? global::System.ReadOnlyMemory<byte>.Empty : data.ToMemory());
#pragma warning restore SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates.
            foreach (var prop in element.EnumerateObject())
            {
                if (prop.NameEquals("cats"u8))
                {
                    if ((prop.Value.ValueKind == global::System.Text.Json.JsonValueKind.Null))
                    {
                        continue;
                    }
                    global::System.Collections.Generic.List<global::Sample.Models.Cat> array = new global::System.Collections.Generic.List<global::Sample.Models.Cat>();
                    foreach (var item in prop.Value.EnumerateArray())
                    {
                        array.Add(global::Sample.Models.Cat.DeserializeCat(item, options));
                    }
                    cats = array;
                    continue;
                }
                if (prop.NameEquals("names"u8))
                {
                    global::System.Collections.Generic.List<string> array = new global::System.Collections.Generic.List<string>();
                    foreach (var item in prop.Value.EnumerateArray())
                    {
                        if ((item.ValueKind == global::System.Text.Json.JsonValueKind.Null))
                        {
                            array.Add(null);
                        }
                        else
                        {
                            array.Add(item.GetString());
                        }
                    }
                    names = array;
                    continue;
                }
                if (prop.NameEquals("optionalNames"u8))
                {
                    if ((prop.Value.ValueKind == global::System.Text.Json.JsonValueKind.Null))
                    {
                        continue;
                    }
                    global::System.Collections.Generic.List<string> array = new global::System.Collections.Generic.List<string>();
                    foreach (var item in prop.Value.EnumerateArray())
                    {
                        if ((item.ValueKind == global::System.Text.Json.JsonValueKind.Null))
                        {
                            array.Add(null);
                        }
                        else
                        {
                            array.Add(item.GetString());
                        }
                    }
                    optionalNames = array;
                    continue;
                }
                patch.Set([.. "$."u8, .. global::System.Text.Encoding.UTF8.GetBytes(prop.Name)], prop.Value.GetUtf8Bytes());
            }
            return new global::Sample.Models.DynamicModel((cats ?? new global::Sample.ChangeTrackingList<global::Sample.Models.Cat>()), names, (optionalNames ?? new global::Sample.ChangeTrackingList<string>()), patch);
        }
    }
}
