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

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

public sealed class ListSessionsCommandContractTests
{
    [Fact]
    public void ListSessionsCommand_ShouldExposePlatformNeutralContext()
    {
        AssertProperty<ListSessionsCommand>("Group", typeof(PlatformGroup));
        AssertProperty<ListSessionsCommand>("User", typeof(PlatformUser));
        AssertNoTelegramSpecificProperties<ListSessionsCommand>();
    }

    [Fact]
    public void DeleteSessionCommand_ShouldExposePlatformNeutralContext()
    {
        AssertProperty<DeleteSessionCommand>("SessionId", typeof(Guid));
        AssertProperty<DeleteSessionCommand>("User", typeof(PlatformUser));
        AssertProperty<DeleteSessionCommand>("Group", typeof(PlatformGroup));
        AssertProperty<DeleteSessionCommand>("ScheduleMessage", typeof(PlatformMessageRef));
        AssertNoTelegramSpecificProperties<DeleteSessionCommand>();
    }

    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);
    }
}
