using GmRelay.Bot.Features.Sessions.ListSessions;
using GmRelay.Shared.Domain;

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

public sealed class SessionListMessageRendererTests
{
    [Fact]
    public void Render_ShouldIncludeManagerActions_WhenUserCanManage()
    {
        var sessionId = Guid.NewGuid();
        var sessions = new[]
        {
            new SessionListItemDto(
                sessionId,
                "Ravenloft",
                new DateTime(2026, 5, 7, 16, 30, 0, DateTimeKind.Utc),
                SessionStatus.Planned,
                4,
                3,
                1,
                true)
        };

        var result = SessionListMessageRenderer.Render(sessions);
        Assert.NotNull(result.Markup);
        var buttons = result.Markup.InlineKeyboard.SelectMany(row => row).ToList();

        Assert.Contains("Ravenloft", result.Text);
        Assert.Collection(
            buttons.Select(button => button.CallbackData),
            callbackData => Assert.Equal($"cancel_session:{sessionId}", callbackData),
            callbackData => Assert.Equal($"reschedule_session:{sessionId}", callbackData),
            callbackData => Assert.Equal($"promote_waitlist:{sessionId}", callbackData),
            callbackData => Assert.Equal($"delete_session:{sessionId}", callbackData));
    }

    [Fact]
    public void Render_ShouldHideManagerActions_WhenUserCannotManage()
    {
        var sessions = new[]
        {
            new SessionListItemDto(
                Guid.NewGuid(),
                "Ravenloft",
                new DateTime(2026, 5, 7, 16, 30, 0, DateTimeKind.Utc),
                SessionStatus.Planned,
                4,
                3,
                1,
                false)
        };

        var result = SessionListMessageRenderer.Render(sessions);

        Assert.Null(result.Markup);
    }
}
