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

public sealed class CreateSessionHandlerTests
{
    [Fact]
    public async Task SharedHandler_ShouldExist_AndBePlatformNeutral()
    {
        var handler = await ReadRepositoryFileAsync("src/GmRelay.Shared/Features/Sessions/CreateSession/CreateSessionHandler.cs");

        Assert.Contains("CreateSessionCommand", handler, StringComparison.Ordinal);
        Assert.Contains("CreateSessionResult", handler, StringComparison.Ordinal);
        Assert.Contains("command.User", handler, StringComparison.Ordinal);
        Assert.Contains("command.Group", handler, StringComparison.Ordinal);
        Assert.DoesNotContain("ITelegramBotClient", handler, StringComparison.Ordinal);
        Assert.DoesNotContain("Telegram.Bot", handler, StringComparison.Ordinal);
        Assert.DoesNotContain("InlineKeyboardMarkup", handler, StringComparison.Ordinal);
        Assert.DoesNotContain("MessageThreadId", handler, 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}'.");
    }
}
