using System;
using System.Collections.Generic;

namespace NT8.Core.Common.Models
{
    /// <summary>
    /// Strategy trading intent - what the strategy wants to do
    /// This is the output of strategy logic, input to risk management
    /// </summary>
    public class StrategyIntent
    {
        /// <summary>
        /// Unique identifier for this intent
        /// </summary>
        public string IntentId { get; private set; }

        /// <summary>
        /// Timestamp when intent was generated
        /// </summary>
        public DateTime Timestamp { get; private set; }

        /// <summary>
        /// Trading symbol
        /// </summary>
        public string Symbol { get; set; }

        /// <summary>
        /// Order side
        /// </summary>
        public OrderSide Side { get; set; }

        /// <summary>
        /// Entry order type
        /// </summary>
        public OrderType EntryType { get; set; }

        /// <summary>
        /// Optional limit price
        /// </summary>
        public double? LimitPrice { get; set; }

        /// <summary>
        /// Stop loss in ticks
        /// </summary>
        public int StopTicks { get; set; }

        /// <summary>
        /// Optional profit target in ticks
        /// </summary>
        public int? TargetTicks { get; set; }

        /// <summary>
        /// Strategy confidence level (0.0 to 1.0)
        /// </summary>
        public double Confidence { get; set; }

        /// <summary>
        /// Human-readable reason for trade
        /// </summary>
        public string Reason { get; set; }

        /// <summary>
        /// Additional strategy-specific data
        /// </summary>
        public Dictionary<string, object> Metadata { get; set; }

        /// <summary>
        /// Constructor for StrategyIntent
        /// </summary>
        public StrategyIntent(
            string symbol,
            OrderSide side,
            OrderType entryType,
            double? limitPrice,
            int stopTicks,
            int? targetTicks,
            double confidence,
            string reason,
            Dictionary<string, object> metadata)
        {
            IntentId = Guid.NewGuid().ToString();
            Timestamp = DateTime.UtcNow;
            Symbol = symbol;
            Side = side;
            EntryType = entryType;
            LimitPrice = limitPrice;
            StopTicks = stopTicks;
            TargetTicks = targetTicks;
            Confidence = confidence;
            Reason = reason;
            Metadata = metadata ?? new Dictionary<string, object>();
        }

        /// <summary>
        /// Validate intent has required fields
        /// </summary>
        public bool IsValid()
        {
            return !String.IsNullOrEmpty(Symbol) &&
                   StopTicks > 0 &&
                   Confidence >= 0.0 && Confidence <= 1.0 &&
                   Side != OrderSide.Flat &&
                   !String.IsNullOrEmpty(Reason);
        }
    }

    /// <summary>
    /// Order side enumeration
    /// </summary>
    public enum OrderSide
    {
        /// <summary>
        /// Buy order
        /// </summary>
        Buy = 1,

        /// <summary>
        /// Sell order
        /// </summary>
        Sell = -1,

        /// <summary>
        /// Close position
        /// </summary>
        Flat = 0
    }

    /// <summary>
    /// Order type enumeration
    /// </summary>
    public enum OrderType
    {
        /// <summary>
        /// Market order
        /// </summary>
        Market,

        /// <summary>
        /// Limit order
        /// </summary>
        Limit,

        /// <summary>
        /// Stop market order
        /// </summary>
        StopMarket,

        /// <summary>
        /// Stop limit order
        /// </summary>
        StopLimit
    }
}