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

namespace Managing.Domain.Trades
{
    public class Position
    {
        public Position(string identifier, string accountName, TradeDirection originDirection, Ticker ticker,
            MoneyManagement moneyManagement, PositionInitiator positionInitiator, DateTime date, User user)
        {
            Identifier = identifier;
            AccountName = accountName;
            OriginDirection = originDirection;
            Ticker = ticker;
            MoneyManagement = moneyManagement;
            Initiator = positionInitiator;
            Date = date;
            Status = Initiator == PositionInitiator.PaperTrading ? PositionStatus.Filled : PositionStatus.New;
            User = user;
        }

        [Required] public string AccountName { get; }
        [Required] public DateTime Date { get; set; }
        [Required] public TradeDirection OriginDirection { get; }
        [Required] public Ticker Ticker { get; }
        [Required] public MoneyManagement MoneyManagement { get; }
        [Required] public Trade Open { get; set; }
        [Required] public Trade StopLoss { get; set; }
        [Required] public Trade TakeProfit1 { get; set; }
        public Trade TakeProfit2 { get; set; }
        public ProfitAndLoss ProfitAndLoss { get; set; }
        [Required] public PositionStatus Status { get; set; }
        public string SignalIdentifier { get; set; }
        [Required] public string Identifier { get; set; }
        [Required] public PositionInitiator Initiator { get; set; }
        [Required] public User User { get; set; }

        public bool IsFinished()
        {
            return Status switch
            {
                PositionStatus.Finished => true,
                PositionStatus.Flipped => true,
                _ => false
            };
        }
    }
}