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

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

public sealed class RescheduleCommandContractTests
{
    [Fact]
    public void HandleRescheduleTimeInputCommand_ShouldExposePlatformNeutralContext()
    {
        AssertProperty<HandleRescheduleTimeInputCommand>("User", typeof(PlatformUser));
        AssertProperty<HandleRescheduleTimeInputCommand>("Group", typeof(PlatformGroup));
        AssertProperty<HandleRescheduleTimeInputCommand>("Text", typeof(string));
        AssertNoTelegramSpecificProperties<HandleRescheduleTimeInputCommand>();
    }

    [Fact]
    public void HandleRescheduleVoteCommand_ShouldExposePlatformNeutralContext()
    {
        AssertProperty<HandleRescheduleVoteCommand>("OptionId", typeof(Guid));
        AssertProperty<HandleRescheduleVoteCommand>("User", typeof(PlatformUser));
        AssertProperty<HandleRescheduleVoteCommand>("Group", typeof(PlatformGroup));
        AssertProperty<HandleRescheduleVoteCommand>("InteractionId", typeof(string));
        AssertProperty<HandleRescheduleVoteCommand>("ScheduleMessage", typeof(PlatformMessageRef));
        AssertNoTelegramSpecificProperties<HandleRescheduleVoteCommand>();
    }

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