using GmRelay.Shared.Features.Sessions.CreateSession;
using GmRelay.Shared.Platform;

namespace GmRelay.Bot.Tests.Features.Sessions.CreateSession;

public sealed class CreateSessionCommandContractTests
{
    [Fact]
    public void CreateSessionCommand_ShouldExposePlatformNeutralContext()
    {
        AssertProperty<CreateSessionCommand>("User", typeof(PlatformUser));
        AssertProperty<CreateSessionCommand>("Group", typeof(PlatformGroup));
        AssertProperty<CreateSessionCommand>("Title", typeof(string));
        AssertProperty<CreateSessionCommand>("Link", typeof(string));
        AssertProperty<CreateSessionCommand>("ScheduledTimes", typeof(IReadOnlyList<DateTimeOffset>));
        AssertProperty<CreateSessionCommand>("MaxPlayers", typeof(int?));
        AssertProperty<CreateSessionCommand>("ImageReference", typeof(string));
        AssertNoTelegramSpecificProperties<CreateSessionCommand>();
    }

    private static void AssertProperty<T>(string name, Type expectedType)
    {
        var property = Assert.Single(typeof(T).GetProperties(), p => p.Name == name);
        Assert.Equal(expectedType, property.PropertyType);
    }

    private static void AssertNoTelegramSpecificProperties<T>()
    {
        var names = typeof(T).GetProperties().Select(p => p.Name).ToArray();
        Assert.DoesNotContain(names, name => name.Contains("Telegram", StringComparison.Ordinal));
        Assert.DoesNotContain("ChatId", names);
        Assert.DoesNotContain("MessageId", names);
        Assert.DoesNotContain("TelegramUserId", names);
        Assert.DoesNotContain("TelegramUsername", names);
    }
}
