using Managing.Domain.Candles;
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 ThreeWhiteSoldiersStrategy : Strategy
    {
        public ThreeWhiteSoldiersStrategy(string name, int period)
            : base(name, StrategyType.ThreeWhiteSoldiers)
        {
            Period = period;
        }

        public TradeDirection Direction { get; }

        public override List<Signal> Run()
        {
            var signals = new List<Signal>();

            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 StrategiesResultBase GetStrategyValues()
        {
            throw new NotImplementedException();
        }
    }
}