//+------------------------------------------------------------------+
//|                                             PositionSnapshot.mqh |
//+------------------------------------------------------------------+

#ifndef POSITIONSNAPSHOT_MQH
#define POSITIONSNAPSHOT_MQH

//+------------------------------------------------------------------+
//| Plain data holder for one open position.                         |
//| Both CPositionReader and CHtmlBuilder depend on this definition, |
//| so it lives in its own file to guarantee a single shared layout. |
//+------------------------------------------------------------------+
struct CPositionSnapshot
  {
private:
   //--- No private members; all fields are intentionally public so that
   //--- the reader and builder can access them without accessor overhead.

public:
   ulong              ticket;         // Unique position ticket number assigned by the broker.
   string             symbol;         // Traded instrument name, e.g. "EURUSD" or "XAUUSD".
   ENUM_POSITION_TYPE type;           // Direction of the trade: POSITION_TYPE_BUY or POSITION_TYPE_SELL.
   double             volume;         // Position size in lots.
   double             open_price;     // Price at which the position was opened.
   double             current_price;  // Live market price at the moment of the snapshot.
   double             stop_loss;      // Stop-loss level; zero if the trader has not set one.
   double             take_profit;    // Take-profit level; zero if the trader has not set one.
   double             profit;         // Floating profit in account currency, excluding swap.
   double             swap;           // Accumulated swap charges on the position.
   string             comment;        // Free-text comment attached to the position by the trader or EA.
   datetime           open_time;      // Server time at which the position was opened.

   //--- const qualifier allows these methods to be called on a
   //--- const reference, which is how BuildTableRow() receives snap.
   string             TypeString(void) const;
   string             ProfitColor(void) const;
  };

//+------------------------------------------------------------------+
//| Returns "BUY" when the position is long, "SELL" when short.      |
//| Declared const because it reads fields only and is called from   |
//| BuildTableRow(), which receives the snapshot as a const ref.     |
//+------------------------------------------------------------------+
string CPositionSnapshot::TypeString(void) const
  {
//--- return the buy label when the type matches the buy constant
   if(type == POSITION_TYPE_BUY)
     {
      return("BUY");
     }
//--- every other value of ENUM_POSITION_TYPE for an open position
//--- is POSITION_TYPE_SELL, so fall through to the sell label
   return("SELL");
  }

//+------------------------------------------------------------------+
//| Maps the profit sign to a light-theme row background tint.       |
//| Pale tints are used instead of saturated fills so that dark body |
//| text remains legible against the white page background, which is |
//| required for MQL5 article publication screenshots.               |
//| Declared const because it reads the profit field only and is     |
//| called from BuildTableRow() via a const reference parameter.     |
//+------------------------------------------------------------------+
string CPositionSnapshot::ProfitColor(void) const
  {
//--- a strictly positive profit earns a pale green background row
   if(profit > 0.0)
     {
      return("#C8E6C9");
     }
//--- a strictly negative profit earns a pale rose background row
   if(profit < 0.0)
     {
      return("#FFCDD2");
     }
//--- exactly zero profit receives a light grey background
   return("#F5F5F5");
  }

#endif // POSITIONSNAPSHOT_MQH
//+------------------------------------------------------------------+