namespace Books.E2E.Tests.Actions;

/// <summary>
/// Extension methods to enable fluent async chaining.
/// Allows patterns like: await Actions.Given.UserIsAuthenticated().When.UserNavigatesToCompanySetup()...
/// </summary>
public static class FluentExtensions
{
    // GivenActions extensions
    public static async Task<WhenActions> When(this Task<GivenActions> task)
    {
        var given = await task;
        return given.When;
    }

    // WhenActions extensions
    public static async Task<WhenActions> And(this Task<WhenActions> task)
    {
        return await task;
    }

    public static async Task<WhenActions> UserNavigatesToCompanySetup(this Task<WhenActions> task)
    {
        var when = await task;
        return await when.UserNavigatesToCompanySetup();
    }

    public static async Task<WhenActions> UserEntersCompanyName(this Task<WhenActions> task, string name)
    {
        var when = await task;
        return await when.UserEntersCompanyName(name);
    }

    public static async Task<WhenActions> UserEntersValidCvr(this Task<WhenActions> task)
    {
        var when = await task;
        return await when.UserEntersValidCvr();
    }

    public static async Task<WhenActions> UserEntersCvr(this Task<WhenActions> task, string cvr)
    {
        var when = await task;
        return await when.UserEntersCvr(cvr);
    }

    public static async Task<WhenActions> UserSelectsCountry(this Task<WhenActions> task, string country)
    {
        var when = await task;
        return await when.UserSelectsCountry(country);
    }

    public static async Task<WhenActions> UserSelectsCurrency(this Task<WhenActions> task, string currency)
    {
        var when = await task;
        return await when.UserSelectsCurrency(currency);
    }

    public static async Task<WhenActions> UserSelectsFiscalYearStartMonth(this Task<WhenActions> task, int month)
    {
        var when = await task;
        return await when.UserSelectsFiscalYearStartMonth(month);
    }

    public static async Task<WhenActions> UserSelectsVatRegistered(this Task<WhenActions> task, bool isRegistered)
    {
        var when = await task;
        return await when.UserSelectsVatRegistered(isRegistered);
    }

    public static async Task<WhenActions> UserSelectsVatPeriod(this Task<WhenActions> task, string period)
    {
        var when = await task;
        return await when.UserSelectsVatPeriod(period);
    }

    public static async Task<WhenActions> UserClicksNext(this Task<WhenActions> task)
    {
        var when = await task;
        return await when.UserClicksNext();
    }

    public static async Task<WhenActions> UserClicksBack(this Task<WhenActions> task)
    {
        var when = await task;
        return await when.UserClicksBack();
    }

    public static async Task<ThenAssertions> UserSubmitsCompanyForm(this Task<WhenActions> task)
    {
        var when = await task;
        return await when.UserSubmitsCompanyForm();
    }

    public static async Task<ThenAssertions> UserClicksGoToDashboard(this Task<WhenActions> task)
    {
        var when = await task;
        return await when.UserClicksGoToDashboard();
    }

    public static async Task<ThenAssertions> Then(this Task<WhenActions> task)
    {
        var when = await task;
        return when.Then;
    }

    // ThenAssertions extensions
    public static async Task<ThenAssertions> And(this Task<ThenAssertions> task)
    {
        return await task;
    }

    public static async Task<ThenAssertions> UserIsRedirectedToDashboard(this Task<ThenAssertions> task)
    {
        var then = await task;
        return await then.UserIsRedirectedToDashboard();
    }

    public static async Task<ThenAssertions> UserSeesSuccessMessage(this Task<ThenAssertions> task)
    {
        var then = await task;
        return await then.UserSeesSuccessMessage();
    }

    public static async Task<ThenAssertions> CompanyIsCreated(this Task<ThenAssertions> task)
    {
        var then = await task;
        return await then.CompanyIsCreated();
    }

    public static async Task<ThenAssertions> ValidationErrorIsShown(this Task<ThenAssertions> task, string expectedMessage)
    {
        var then = await task;
        return await then.ValidationErrorIsShown(expectedMessage);
    }

    public static async Task<ThenAssertions> ErrorMessageIsShown(this Task<ThenAssertions> task, string expectedMessage)
    {
        var then = await task;
        return await then.ErrorMessageIsShown(expectedMessage);
    }

    public static async Task<ThenAssertions> UserIsOnPage(this Task<ThenAssertions> task, string expectedPath)
    {
        var then = await task;
        return await then.UserIsOnPage(expectedPath);
    }

    public static async Task<ThenAssertions> TextIsVisible(this Task<ThenAssertions> task, string text)
    {
        var then = await task;
        return await then.TextIsVisible(text);
    }
}
