using System.Collections.Concurrent;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text.Json;
using AyCode.Core.Helpers;

namespace AyCode.Core.Serializers.Jsons;

public static partial class AcJsonSerializer
{
    private sealed class JsonSerializeTypeMetadata : SerializeTypeMetadataBase
    {
        public PropertyAccessor[] Properties { get; }

        public JsonSerializeTypeMetadata(
            [DynamicallyAccessedMembers(RequiredMembers)] Type type)
            : base(type, JsonUtilities.HasJsonIgnoreAttribute)
        {
            // Use pre-computed ReadableProperties directly - no method call overhead!
            Properties = ReadableProperties
                .Select(p => new PropertyAccessor(p, type))
                .ToArray();
        }
    }

    /// <summary>
    /// JSON serialization property accessor.
    /// </summary>
    private sealed class PropertyAccessor : JsonPropertyAccessorBase
    {
        public PropertyAccessor(PropertyInfo prop, Type declaringType) 
            : base(prop, declaringType)
        {
        }
    }
}
