using System;

namespace Predictalytics.Domain.Entities;

/// <summary>
/// Represents a trader's position in a specific market outcome.
/// Tracks shares held, average purchase price, and realized profit/loss.
/// </summary>
public class TraderPosition
{
    public int Id { get; set; }

    /// <summary>Foreign key to the trader.</summary>
    public int TraderId { get; set; }

    /// <summary>Foreign key to the resolved market outcome.</summary>
    public int MarketOutcomeId { get; set; }

    /// <summary>Number of shares currently held.</summary>
    public decimal SharesHeld { get; set; }

    /// <summary>Average purchase cost per share.</summary>
    public decimal AvgCost { get; set; }

    /// <summary>Realized profit/loss from closed portions of this position.</summary>
    public decimal RealizedPnl { get; set; }

    /// <summary>ID of the last trade applied to this position.</summary>
    public long LastAppliedTradeId { get; set; }

    /// <summary>Timestamp of the last trade applied. Used to detect out-of-order inserts.</summary>
    public DateTime? LastTradeExecutedAt { get; set; }

    /// <summary>True if old trades for this position have been pruned/deleted. Prevents resetting.</summary>
    public bool IsHistoryPruned { get; set; }

    /// <summary>When this position was last updated.</summary>
    public DateTime LastUpdatedAt { get; set; } = DateTime.UtcNow;

    // Navigation properties
    public Trader Trader { get; set; } = null!;
    public MarketOutcome MarketOutcome { get; set; } = null!;
}
