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

namespace Managing.Domain.Bots
{
    public class Bot
    {
        public User User { get; set; }
        public Guid Identifier { get; set; }
        public string Name { get; set; }
        public Ticker Ticker { get; set; }
        public BotStatus Status { get; set; }
        public DateTime StartupTime { get; set; }
        public DateTime CreateDate { get; set; }

        // Runtime tracking fields
        public DateTime? LastStartTime { get; set; }
        public DateTime? LastStopTime { get; set; }
        public long AccumulatedRunTimeSeconds { get; set; }

        public int TradeWins { get; set; }
        public int TradeLosses { get; set; }
        public decimal Pnl { get; set; }
        public decimal NetPnL { get; set; }
        public decimal Roi { get; set; }
        public decimal Volume { get; set; }
        public decimal Fees { get; set; }
        public int LongPositionCount { get; set; }
        public int ShortPositionCount { get; set; }
        
        /// <summary>
        /// Gets the total runtime in seconds, including the current session if the bot is running
        /// </summary>
        public long GetTotalRuntimeSeconds()
        {
            var totalSeconds = AccumulatedRunTimeSeconds;
            
            // If bot is currently running, add current session time
            if (Status == BotStatus.Running && LastStartTime.HasValue)
            {
                var currentSessionSeconds = (long)(DateTime.UtcNow - LastStartTime.Value).TotalSeconds;
                totalSeconds += currentSessionSeconds;
            }
            
            return totalSeconds;
        }
    }
}