using Managing.Domain.Candles;
using Managing.Domain.Indicators;
using Managing.Domain.Shared.Rules;
using Managing.Domain.Strategies.Base;
using Managing.Domain.Strategies.Rules;
using static Managing.Common.Enums;

namespace Managing.Domain.Strategies.Signals
{
    public class ThreeWhiteSoldiersIndicatorBase : IndicatorBase
    {
        public ThreeWhiteSoldiersIndicatorBase(string name, int period)
            : base(name, IndicatorType.ThreeWhiteSoldiers)
        {
            Period = period;
        }

        public TradeDirection Direction { get; }

        public override List<LightSignal> Run(HashSet<Candle> candles)
        {
            var signals = new List<LightSignal>();

            if (candles.Count <= 3)
            {
                return null;
            }

            try
            {
                var lastFourCandles = candles.TakeLast(4);
                Candle previousCandles = null;

                foreach (var currentCandle in lastFourCandles)
                {
                    if (Direction == TradeDirection.Long)
                    {
                        Check.That(new CloseHigherThanThePreviousHigh(previousCandles, currentCandle));
                    }
                    else
                    {
                        Check.That(new CloseLowerThanThePreviousHigh(previousCandles, currentCandle));
                    }

                    previousCandles = currentCandle;
                }

                return signals;
            }
            catch (RuleException)
            {
                return null;
            }
        }

        public override IndicatorsResultBase GetIndicatorValues(HashSet<Candle> candles)
        {
            throw new NotImplementedException();
        }
    }
}