//+------------------------------------------------------------------+
//|                                                   TradeEvent.mqh |
//+------------------------------------------------------------------+

#ifndef TRADEEVENT_MQH
#define TRADEEVENT_MQH

//+------------------------------------------------------------------+
//| Holds all fields describing one deal event for database storage. |
//| Both CSqliteBridge and the EA's OnTrade() handler read this      |
//| struct directly, so all fields are public.                       |
//+------------------------------------------------------------------+
struct CTradeEvent
  {
private:
   //--- no private members; direct field access is intentional

public:
   string            event_type;    // "OPEN", "CLOSE", or "BALANCE"
   ulong             deal_ticket;   // unique deal identifier
   ulong             order_ticket;  // originating order ticket
   ulong             position_id;   // parent position identifier
   string            symbol;        // traded instrument; empty for balance events
   ENUM_DEAL_TYPE    direction;     // DEAL_TYPE_BUY, DEAL_TYPE_SELL, or DEAL_TYPE_BALANCE
   double            volume;        // lot size; zero for balance events
   double            price;         // deal fill price
   double            stop_loss;     // SL at time of deal; zero if unset
   double            take_profit;   // TP at time of deal; zero if unset
   double            profit;        // deal profit in account currency
   double            swap;          // swap charge on this deal
   double            commission;    // commission charge on this deal
   long              magic;         // EA magic number; zero if manual trade
   string            comment;       // deal comment from broker or EA
   long              account_id;    // account number for multi-account setups
   datetime          event_time;    // server time of the deal execution

   string            DirectionString(void) const;
   string            FormatTime(void) const;
  };

//+------------------------------------------------------------------+
//| Returns a readable direction label for the deal type.            |
//| Returns empty string for balance and other non-directional types.|
//+------------------------------------------------------------------+
string CTradeEvent::DirectionString(void) const
  {
   if(direction == DEAL_TYPE_BUY)
      return("BUY");
   if(direction == DEAL_TYPE_SELL)
      return("SELL");
   return(""); // balance, credit, and other non-directional deal types
  }

//+------------------------------------------------------------------+
//| Returns the event time as a sortable text string.                |
//| Format: YYYY.MM.DD HH:MM:SS, consistent across all rows.         |
//+------------------------------------------------------------------+
string CTradeEvent::FormatTime(void) const
  {
   return(TimeToString(event_time, TIME_DATE | TIME_MINUTES | TIME_SECONDS));
  }

#endif // TRADEEVENT_MQH
//+------------------------------------------------------------------+