using System.ComponentModel;
using System.Linq;
using System.Reflection;
using PolyTraderSharp.Models;
using Xunit;

namespace PolyTrader.Tests
{
    /// <summary>
    /// Fixiert die entscheidungsrelevanten Default-Werte und stellt sicher, dass alle
    /// einstellbaren Settings eine [Description] als Erklärung tragen (Richards Vorgabe).
    /// </summary>
    public class SettingsDefaultsTests
    {
        [Fact]
        public void ProfitTarget_defaults_to_9999_inactive()
        {
            Assert.Equal(9999m, new CopyTradingAccountSettings().ProfitTarget);
        }

        [Fact]
        public void New_account_settings_have_expected_defaults()
        {
            var s = new CopyTradingAccountSettings();
            Assert.Equal(15.0m, s.SellFloorPct);
            Assert.Equal(5.0m, s.MaxSpreadPct);
            Assert.Equal(10.0m, s.MinSellRatioPct);
        }

        [Fact]
        public void Master_auto_pause_is_on_by_default_maker_off()
        {
            var t = new TrackedTrader();
            Assert.True(t.AutoPauseEnabled);
            Assert.False(t.MakerEntry);
        }

        [Theory]
        [InlineData(typeof(CopyTradingAccountSettings))]
        [InlineData(typeof(TrackedTrader))]
        public void All_browsable_writable_settings_have_a_description(System.Type type)
        {
            var missing = type.GetProperties(BindingFlags.Public | BindingFlags.Instance)
                .Where(p => p.CanWrite)
                .Where(p => p.GetCustomAttribute<BrowsableAttribute>()?.Browsable != false)
                .Where(p => string.IsNullOrWhiteSpace(p.GetCustomAttribute<DescriptionAttribute>()?.Description))
                .Select(p => p.Name)
                .ToList();

            Assert.True(missing.Count == 0, $"Ohne [Description]: {string.Join(", ", missing)}");
        }
    }
}
