using GmRelay.DiscordBot.Infrastructure.Discord;

namespace GmRelay.Bot.Tests.Discord;

public sealed class DiscordPermissionCheckerTests
{
    [Fact]
    public void CanManageSchedule_WhenUserIsGuildOwner_ReturnsTrue()
    {
        var checker = new DiscordPermissionChecker();
        var result = checker.CanManageSchedule(
            guildOwnerId: 123456789ul,
            userId: 123456789ul,
            dbManagerUserIds: Array.Empty<ulong>(),
            resolvedPermissions: 0);

        Assert.True(result);
    }

    [Fact]
    public void CanManageSchedule_WhenUserHasAdministratorPermission_ReturnsTrue()
    {
        var checker = new DiscordPermissionChecker();
        var result = checker.CanManageSchedule(
            guildOwnerId: 123456789ul,
            userId: 987654321ul,
            dbManagerUserIds: Array.Empty<ulong>(),
            resolvedPermissions: 0x8); // Administrator

        Assert.True(result);
    }

    [Fact]
    public void CanManageSchedule_WhenUserIsDbManager_ReturnsTrue()
    {
        var checker = new DiscordPermissionChecker();
        var managerId = 555ul;
        var result = checker.CanManageSchedule(
            guildOwnerId: 123456789ul,
            userId: managerId,
            dbManagerUserIds: new[] { managerId },
            resolvedPermissions: 0);

        Assert.True(result);
    }

    [Fact]
    public void CanManageSchedule_WhenRegularUser_ReturnsFalse()
    {
        var checker = new DiscordPermissionChecker();
        var result = checker.CanManageSchedule(
            guildOwnerId: 123456789ul,
            userId: 111ul,
            dbManagerUserIds: new[] { 222ul },
            resolvedPermissions: 0);

        Assert.False(result);
    }

    [Fact]
    public void CanManageSchedule_WhenUserHasOtherPermissionButNotAdmin_ReturnsFalse()
    {
        var checker = new DiscordPermissionChecker();
        var result = checker.CanManageSchedule(
            guildOwnerId: 123456789ul,
            userId: 111ul,
            dbManagerUserIds: Array.Empty<ulong>(),
            resolvedPermissions: 0x4); // ManageServer, not Administrator

        Assert.False(result);
    }
}
