using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

// ref link: http://dontcodetired.com/blog/post/Creating-a-Spinner-Animation-in-a-Console-Application-in-C
namespace LibraryPricer
{
/* non funziona bene
//var s = new ConsoleSpinner();
//double fv = 0;
//while (fv == 0)
//{
//    //Thread.Sleep(100); // simulate some work being done
//    fv = CalcFunctions.FairValue(PricesUL, corrMatrix, numSottostanti, num_sims, r, DaysToMaturity, Dividends, Volatility, DaysToObservation, DaysToObservationYFract, CouponValues, CouponTriggers, AutocallValues, AutocallTriggers, MemoryFlags, PDI_Style, PDI_Strike, PDI_Barrier, CapitalValue);
//    s.UpdateProgress();
//}     
*/
    public class ConsoleSpinner
        {
            private int _currentAnimationFrame;

            public ConsoleSpinner()
            {
                SpinnerAnimationFrames = new[]
                                         {
                                         '|',
                                         '/',
                                         '-',
                                         '\\'
                                     };
            }

            public char[] SpinnerAnimationFrames { get; set; }

            public void UpdateProgress()
            {
                // Store the current position of the cursor
                var originalX = Console.CursorLeft;
                var originalY = Console.CursorTop;

                // Write the next frame (character) in the spinner animation
                Console.Write(SpinnerAnimationFrames[_currentAnimationFrame]);

                // Keep looping around all the animation frames
                _currentAnimationFrame++;
                if (_currentAnimationFrame == SpinnerAnimationFrames.Length)
                {
                    _currentAnimationFrame = 0;
                }

                // Restore cursor to original position
                Console.SetCursorPosition(originalX, originalY);
            }
        }
}
