using System;
using System.Collections.Generic;

namespace NT8.Core.Common.Models
{
    /// <summary>
    /// Strategy context - provides market and account information to strategies
    /// </summary>
    public class StrategyContext
    {
        /// <summary>
        /// Trading symbol
        /// </summary>
        public string Symbol { get; set; }

        /// <summary>
        /// Current timestamp
        /// </summary>
        public DateTime CurrentTime { get; set; }

        /// <summary>
        /// Current position information
        /// </summary>
        public Position CurrentPosition { get; set; }

        /// <summary>
        /// Account information
        /// </summary>
        public AccountInfo Account { get; set; }

        /// <summary>
        /// Market session information
        /// </summary>
        public MarketSession Session { get; set; }

        /// <summary>
        /// Additional custom data
        /// </summary>
        public Dictionary<string, object> CustomData { get; set; }

        /// <summary>
        /// Constructor for StrategyContext
        /// </summary>
        public StrategyContext(
            string symbol,
            DateTime currentTime,
            Position currentPosition,
            AccountInfo account,
            MarketSession session,
            Dictionary<string, object> customData)
        {
            Symbol = symbol;
            CurrentTime = currentTime;
            CurrentPosition = currentPosition;
            Account = account;
            Session = session;
            CustomData = customData ?? new Dictionary<string, object>();
        }
    }

    /// <summary>
    /// Position information
    /// </summary>
    public class Position
    {
        /// <summary>
        /// Position symbol
        /// </summary>
        public string Symbol { get; set; }

        /// <summary>
        /// Position quantity
        /// </summary>
        public int Quantity { get; set; }

        /// <summary>
        /// Average entry price
        /// </summary>
        public double AveragePrice { get; set; }

        /// <summary>
        /// Unrealized profit/loss
        /// </summary>
        public double UnrealizedPnL { get; set; }

        /// <summary>
        /// Realized profit/loss
        /// </summary>
        public double RealizedPnL { get; set; }

        /// <summary>
        /// Last update timestamp
        /// </summary>
        public DateTime LastUpdate { get; set; }

        /// <summary>
        /// Constructor for Position
        /// </summary>
        public Position(
            string symbol,
            int quantity,
            double averagePrice,
            double unrealizedPnL,
            double realizedPnL,
            DateTime lastUpdate)
        {
            Symbol = symbol;
            Quantity = quantity;
            AveragePrice = averagePrice;
            UnrealizedPnL = unrealizedPnL;
            RealizedPnL = realizedPnL;
            LastUpdate = lastUpdate;
        }
    }

    /// <summary>
    /// Account information
    /// </summary>
    public class AccountInfo
    {
        /// <summary>
        /// Current account equity
        /// </summary>
        public double Equity { get; set; }

        /// <summary>
        /// Available buying power
        /// </summary>
        public double BuyingPower { get; set; }

        /// <summary>
        /// Today's profit/loss
        /// </summary>
        public double DailyPnL { get; set; }

        /// <summary>
        /// Maximum drawdown
        /// </summary>
        public double MaxDrawdown { get; set; }

        /// <summary>
        /// Last update timestamp
        /// </summary>
        public DateTime LastUpdate { get; set; }

        /// <summary>
        /// Constructor for AccountInfo
        /// </summary>
        public AccountInfo(
            double equity,
            double buyingPower,
            double dailyPnL,
            double maxDrawdown,
            DateTime lastUpdate)
        {
            Equity = equity;
            BuyingPower = buyingPower;
            DailyPnL = dailyPnL;
            MaxDrawdown = maxDrawdown;
            LastUpdate = lastUpdate;
        }
    }

    /// <summary>
    /// Market session information
    /// </summary>
    public class MarketSession
    {
        /// <summary>
        /// Session start time
        /// </summary>
        public DateTime SessionStart { get; set; }

        /// <summary>
        /// Session end time
        /// </summary>
        public DateTime SessionEnd { get; set; }

        /// <summary>
        /// Regular Trading Hours
        /// </summary>
        public bool IsRth { get; set; }

        /// <summary>
        /// Session name
        /// </summary>
        public string SessionName { get; set; }

        /// <summary>
        /// Constructor for MarketSession
        /// </summary>
        public MarketSession(
            DateTime sessionStart,
            DateTime sessionEnd,
            bool isRth,
            string sessionName)
        {
            SessionStart = sessionStart;
            SessionEnd = sessionEnd;
            IsRth = isRth;
            SessionName = sessionName;
        }
    }
}