using Newtonsoft.Json.Linq;
using PlanTempus.Core.Configurations.Common;

namespace PlanTempus.X.TDD.ConfigurationTests;

[TestClass]
public class ConfigurationTests : TestFixture
{
    [TestInitialize]
    public void Init()
    {
    }


    [TestMethod]
    public void ConfigurationSettingsTest()
    {
        var pairs = new List<KeyValuePair<string, JToken>>
        {
            new("Debug", true),
            // Database konfiguration
            new("Database:ConnectionString", "Server=db.example.com;Port=5432"),
            new("Database:Timeout", 30),
            new("Database:UseSSL", true),

            // Logging konfiguration med JObject
            new("Logging:FileOptions", JObject.Parse(@"{
                                'Path': '/var/logs/app.log',
                                'MaxSizeMB': 100,
                                'RetentionDays': 7
                            }")),

            // Feature flags med kompleks konfiguration
            new("Features:Experimental", JObject.Parse(@"{
                                'Enabled': true,
                                'RolloutPercentage': 25,
                                'AllowedUserGroups': ['beta']
                            }")),

            // API endpoints med array
            new("API:Endpoints", "/api/users"),
            new("API:Endpoints", "/api/products")
        };

        var result = KeyValueToJson.Convert(pairs);

        var expected = JObject.Parse(@"{
        'Debug' : true,
        'Database': {
            'ConnectionString': 'Server=db.example.com;Port=5432',
            'Timeout': 30,
            'UseSSL': true
        },
        'Logging': {
            'FileOptions': {
                'Path': '/var/logs/app.log',
                'MaxSizeMB': 100,
                'RetentionDays': 7
            }
        },
        'Features': {
            'Experimental': {
                'Enabled': true,
                'RolloutPercentage': 25,
                'AllowedUserGroups': ['beta']
            }
        },
        'API': {
            'Endpoints': ['/api/users', '/api/products']
        }
    }");

        Assert.IsTrue(JToken.DeepEquals(expected, result));
    }
}