// <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.IDictionary<string, global::Sample.Models.Cat> cats = default;
            global::System.Collections.Generic.IDictionary<string, string> names = default;
            global::System.Collections.Generic.IDictionary<string, 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.Dictionary<string, global::Sample.Models.Cat> dictionary = new global::System.Collections.Generic.Dictionary<string, global::Sample.Models.Cat>();
                    foreach (var prop0 in prop.Value.EnumerateObject())
                    {
                        dictionary.Add(prop0.Name, global::Sample.Models.Cat.DeserializeCat(prop0.Value, options));
                    }
                    cats = dictionary;
                    continue;
                }
                if (prop.NameEquals("names"u8))
                {
                    global::System.Collections.Generic.Dictionary<string, string> dictionary = new global::System.Collections.Generic.Dictionary<string, string>();
                    foreach (var prop0 in prop.Value.EnumerateObject())
                    {
                        if ((prop0.Value.ValueKind == global::System.Text.Json.JsonValueKind.Null))
                        {
                            dictionary.Add(prop0.Name, null);
                        }
                        else
                        {
                            dictionary.Add(prop0.Name, prop0.Value.GetString());
                        }
                    }
                    names = dictionary;
                    continue;
                }
                if (prop.NameEquals("optionalNames"u8))
                {
                    if ((prop.Value.ValueKind == global::System.Text.Json.JsonValueKind.Null))
                    {
                        continue;
                    }
                    global::System.Collections.Generic.Dictionary<string, string> dictionary = new global::System.Collections.Generic.Dictionary<string, string>();
                    foreach (var prop0 in prop.Value.EnumerateObject())
                    {
                        if ((prop0.Value.ValueKind == global::System.Text.Json.JsonValueKind.Null))
                        {
                            dictionary.Add(prop0.Name, null);
                        }
                        else
                        {
                            dictionary.Add(prop0.Name, prop0.Value.GetString());
                        }
                    }
                    optionalNames = dictionary;
                    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.ChangeTrackingDictionary<string, global::Sample.Models.Cat>()), names, (optionalNames ?? new global::Sample.ChangeTrackingDictionary<string, string>()), patch);
        }
    }
}
