namespace GmRelay.Bot.Tests.Discord;

public sealed class DiscordRescheduleDeadlineBoundaryTests
{
    [Fact]
    public async Task DiscordDeadlineService_ShouldUsePlatformMessengerForMessageUpdates()
    {
        var source = await ReadRepositoryFileAsync(
            "src/GmRelay.DiscordBot/Features/Sessions/DiscordRescheduleVotingDeadlineService.cs");

        Assert.DoesNotContain("RestClient", source, StringComparison.Ordinal);
        Assert.DoesNotContain("ModifyMessageAsync", source, StringComparison.Ordinal);
        Assert.Contains("UpdateRescheduleVoteAsync", source, StringComparison.Ordinal);
        Assert.Contains("IPlatformMessenger", source, StringComparison.Ordinal);
    }

    private static async Task<string> ReadRepositoryFileAsync(string relativePath)
    {
        var directory = new DirectoryInfo(AppContext.BaseDirectory);
        while (directory is not null)
        {
            var candidate = Path.Combine(directory.FullName, relativePath);
            if (File.Exists(candidate))
                return await File.ReadAllTextAsync(candidate);

            directory = directory.Parent;
        }

        throw new FileNotFoundException($"Could not locate repository file '{relativePath}'.");
    }
}
