namespace Books.E2E.Tests.TestData;

/// <summary>
/// Generates unique test data for E2E tests.
/// </summary>
public static class TestDataGenerator
{
    private static readonly Random Random = new();
    private static int _counter = 0;

    /// <summary>
    /// Generates a unique company name for testing.
    /// </summary>
    public static string GenerateCompanyName()
    {
        var timestamp = DateTime.Now.ToString("HHmmss");
        return $"E2E Test Virksomhed {timestamp}-{Interlocked.Increment(ref _counter)}";
    }

    /// <summary>
    /// Generates a unique customer name for testing.
    /// </summary>
    public static string GenerateCustomerName()
    {
        var timestamp = DateTime.Now.ToString("HHmmss");
        return $"Test Kunde {timestamp}-{Interlocked.Increment(ref _counter)}";
    }

    /// <summary>
    /// Generates a unique product name for testing.
    /// </summary>
    public static string GenerateProductName()
    {
        var products = new[] { "Konsulenttime", "Support", "Udvikling", "Analyse", "Design", "Test" };
        var product = products[Random.Next(products.Length)];
        return $"{product} E2E-{Interlocked.Increment(ref _counter)}";
    }

    /// <summary>
    /// Generates a unique order line description.
    /// </summary>
    public static string GenerateOrderLineDescription()
    {
        var descriptions = new[]
        {
            "Konsulentbistand",
            "Systemudvikling",
            "Support og vedligeholdelse",
            "Projektledelse",
            "Implementering",
            "Analyse og design"
        };
        return $"{descriptions[Random.Next(descriptions.Length)]} E2E-{Interlocked.Increment(ref _counter)}";
    }

    /// <summary>
    /// Generates a random unit price.
    /// </summary>
    public static decimal GenerateUnitPrice(decimal min = 100m, decimal max = 5000m)
    {
        var range = max - min;
        return Math.Round(min + (decimal)Random.NextDouble() * range, 2);
    }

    /// <summary>
    /// Generates a random quantity.
    /// </summary>
    public static int GenerateQuantity(int min = 1, int max = 100)
    {
        return Random.Next(min, max + 1);
    }

    /// <summary>
    /// Generates a unique reference string.
    /// </summary>
    public static string GenerateReference()
    {
        return $"REF-E2E-{DateTime.Now:yyyyMMdd}-{Interlocked.Increment(ref _counter)}";
    }

    /// <summary>
    /// Generates test notes/description text.
    /// </summary>
    public static string GenerateNotes()
    {
        var notes = new[]
        {
            "Automatiseret E2E test ordre",
            "Test ordre til systemvalidering",
            "Genereret af E2E test suite"
        };
        return $"{notes[Random.Next(notes.Length)]} #{Interlocked.Increment(ref _counter)}";
    }

    /// <summary>
    /// Generates a future date for delivery.
    /// </summary>
    public static DateTime GenerateFutureDeliveryDate(int minDays = 7, int maxDays = 30)
    {
        var days = Random.Next(minDays, maxDays + 1);
        return DateTime.Today.AddDays(days);
    }
}
