using Managing.Domain.Trades;
using Managing.Domain.Users;
using MediatR;
using static Managing.Common.Enums;

namespace Managing.Application.Trading.Commands
{
    public class OpenPositionRequest : IRequest<Position>
    {
        public OpenPositionRequest(
            string accountName,
            LightMoneyManagement moneyManagement,
            TradeDirection direction,
            Ticker ticker,
            PositionInitiator initiator,
            DateTime date,
            User user,
            decimal amountToTrade,
            bool isForPaperTrading = false,
            decimal? price = null,
            string signalIdentifier = null,
            Guid? initiatorIdentifier = null)
        {
            AccountName = accountName;
            MoneyManagement = moneyManagement;
            Direction = direction;
            Ticker = ticker;
            Initiator = initiator;
            Date = date;
            User = user;

            if (amountToTrade <= 10)
            {
                throw new ArgumentException("Bot trading balance must be greater than zero", nameof(amountToTrade));
            }

            AmountToTrade = amountToTrade;

            IsForPaperTrading = isForPaperTrading;
            Price = price;
            SignalIdentifier = signalIdentifier;
            InitiatorIdentifier = initiatorIdentifier ?? throw new ArgumentNullException(nameof(initiatorIdentifier), "InitiatorIdentifier is required");
        }

        public string SignalIdentifier { get; set; }
        public string AccountName { get; }
        public LightMoneyManagement MoneyManagement { get; }
        public TradeDirection Direction { get; }
        public Ticker Ticker { get; }
        public bool IsForPaperTrading { get; }
        public decimal? Price { get; }
        public decimal AmountToTrade { get; }
        public DateTime Date { get; }
        public PositionInitiator Initiator { get; }
        public User User { get; }
        public Guid InitiatorIdentifier { get; }
    }
}