namespace ESuite.UI.E2E.Helpers
{
    public class RetryHelper
    {
        public static void Retry(Action action, int maxRetries = 3, int delayInMilliseconds = 1500)
        {
            int attempts = 0;
            while (true)
            {
                try
                {
                    attempts++;
                    action();
                    return;
                }
                catch (Exception ex)
                {
                    if (attempts >= maxRetries)
                        throw new Exception($"Action failed after {maxRetries} retries.", ex);

                    Console.WriteLine($"Attempt {attempts} failed: {ex.Message}. Retrying in {delayInMilliseconds}ms...");
                    Thread.Sleep(delayInMilliseconds);
                }
            }
        }
    }
}
