using Managing.Common;
using Managing.Domain.Candles;
using Skender.Stock.Indicators;

namespace Managing.Domain.Strategies.Base;

public abstract class EmaBaseIndicatorBase : IndicatorBase
{
    protected EmaBaseIndicatorBase(string name, Enums.IndicatorType type) : base(name, type)
    {
    }

    protected List<CandleEma> MapEmaToCandle(List<EmaResult> ema, IEnumerable<Candle> candles)
    {
        var emaList = new List<CandleEma>();
        foreach (var candle in candles)
        {
            var currentEma = ema.Find(candle.Date);
            if (currentEma != null && currentEma.Ema.HasValue)
            {
                emaList.Add(new CandleEma()
                {
                    Close = candle.Close,
                    Open = candle.Open,
                    Date = candle.Date,
                    Ticker = candle.Ticker,
                    Exchange = candle.Exchange,
                    Ema = currentEma.Ema.Value,
                });
            }
        }

        return emaList;
    }

    public class CandleEma : Candle
    {
        public double Ema { get; set; }
    }
}