using System.ComponentModel.DataAnnotations;
using Managing.Core;
using Managing.Domain.Candles;
using Managing.Domain.Users;
using static Managing.Common.Enums;

namespace Managing.Domain.Strategies
{
    public class Signal : ValueObject
    {
        [Required] public SignalStatus Status { get; set; }
        [Required] public TradeDirection Direction { get; }
        [Required] public Confidence Confidence { get; private set; }
        [Required] public Timeframe Timeframe { get; }
        [Required] public DateTime Date { get; private set; }
        [Required] public Candle Candle { get; }
        [Required] public string Identifier { get; }
        [Required] public Ticker Ticker { get; }
        [Required] public TradingExchanges Exchange { get; set; }
        [Required] public StrategyType StrategyType { get; set; }
        [Required] public SignalType SignalType { get; set; }
        public User User { get; set; }

        public Signal(Ticker ticker, TradeDirection direction, Confidence confidence, Candle candle, DateTime date,
            TradingExchanges exchange, StrategyType strategyType, SignalType signalType, User user = null)
        {
            Direction = direction;
            Confidence = confidence;
            Candle = candle;
            Date = date;
            Ticker = ticker;
            Exchange = exchange;
            Status = SignalStatus.WaitingForPosition;
            StrategyType = strategyType;
            User = user;

            Identifier = $"{StrategyType}-{direction}-{ticker}-{candle?.Close}-{date:yyyyMMdd-HHmmss}";
            SignalType = signalType;
        }

        public void SetConfidence(Confidence confidence)
        {
            Confidence = confidence;
        }

        protected override IEnumerable<object> GetEqualityComponents()
        {
            yield return Direction;
            yield return Confidence;
            yield return Date;
        }
    }
}