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

namespace Managing.Domain.Trades
{
    [GenerateSerializer]
    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;
        }

        [Id(0)]
        [Required] public decimal Fee { get; set; }
        
        [Id(1)]
        [Required] public DateTime Date { get; set; }
        
        [Id(2)]
        [Required] public TradeDirection Direction { get; set; }
        
        [Id(3)]
        [Required] public TradeStatus Status { get; set; }
        
        [Id(4)]
        [Required] public TradeType TradeType { get; set; }
        
        [Id(5)]
        [Required] public Ticker Ticker { get; set; }
        
        [Id(6)]
        [Required] public decimal Quantity { get; set; }
        
        [Id(7)]
        [Required] public decimal Price { get; set; }
        
        [Id(8)]
        [Required] public decimal Leverage { get; set; }
        
        [Id(9)]
        [Required] public string ExchangeOrderId { get; set; }
        
        [Id(10)]
        [Required] public string Message { get; 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);
        }
    }
}