using AyCode.Core.Extensions;
using AyCode.Core.Serializers.Jsons;

namespace AyCode.Core.Tests;

public class TestChainApi
{
    public static void RunTest()
    {
        var json = """{"Name":"John","Age":30,"City":"New York"}""";

        // Test 1: DeserializeChain
        Console.WriteLine("=== Test DeserializeChain ===");
        using (var chain = json.JsonToChain<Person>())
        {
            var person = chain.Value;
            Console.WriteLine($"Person: {person?.Name}, {person?.Age}");

            var dict = chain.ThenDeserialize<Dictionary<string, object>>();
            Console.WriteLine($"Dict: {dict?.Count} keys");

            var person2 = chain.ThenDeserialize<Person>();
            Console.WriteLine($"Person2: {person2?.Name}, {person2?.Age}");
        }

        // Test 2: PopulateChain
        Console.WriteLine("\n=== Test PopulateChain ===");
        var target1 = new Person { Name = "Old", Age = 99, City = "Old City" };
        var target2 = new Person { Name = "Old2", Age = 88, City = "Old City 2" };

        using (var chain = json.JsonToChain(target1))
        {
            Console.WriteLine($"Target1 after populate: {target1.Name}, {target1.Age}, {target1.City}");

            chain.ThenPopulate(target2);
            Console.WriteLine($"Target2 after populate: {target2.Name}, {target2.Age}, {target2.City}");
        }

        Console.WriteLine("\n=== All tests passed! ===");
    }
}

public class Person
{
    public string Name { get; set; } = "";
    public int Age { get; set; }
    public string City { get; set; } = "";
}
