using System.ComponentModel.DataAnnotations;
using static Managing.Common.Enums;

namespace Managing.Domain.Trades
{
    public class Trade
    {
        public Trade(DateTime date, TradeDirection direction, TradeStatus status, TradeType tradeType, Ticker ticker, 
            decimal quantity, decimal price, decimal? leverage, string exchangeOrderId, string message)
        {
            Date = date;
            Direction = direction;
            Status = status;
            TradeType = tradeType;
            Ticker = ticker;
            Quantity = quantity;
            Price = price;
            Leverage = leverage.GetValueOrDefault();
            ExchangeOrderId = exchangeOrderId;
            Message = message;
            Fee = 0;
        }

        public decimal Fee { get; set; }
        [Required]
        public DateTime Date { get; private set; }
        [Required]
        public TradeDirection Direction { get; }
        [Required]
        public TradeStatus Status { get; private set; }
        [Required]
        public TradeType TradeType { get; }
        [Required]
        public Ticker Ticker { get; }
        [Required]
        public decimal Quantity { get; set; }
        [Required]
        public decimal Price { get; set; }
        public decimal Leverage { get; }
        [Required]
        public string ExchangeOrderId { get; private set; }
        public string Message { get; private set; }

        public void SetStatus(TradeStatus status)
        {
            Status = status;
        }

        public void SetDate(DateTime date)
        {
            Date = date;
        }

        public void SetExchangeOrderId(string exchangeOrderId)
        {
            ExchangeOrderId = exchangeOrderId;
        }

        public void SetMessage(string message)
        {
            Message = message;
        }

        public void SetQuantity(decimal quantity, int precision)
        {
            Quantity = Math.Round(quantity, precision);
        }

        public void SetPrice(decimal price, int precision)
        {
            Price = Math.Round(price, precision);
        }
    }
}
