//+------------------------------------------------------------------+
//|                                             RegistryMetadata.mqh |
//|        Adds run provenance fields to the CSV export row schema   |
//+------------------------------------------------------------------+
#property strict

#ifndef REGISTRY_METADATA_MQH
#define REGISTRY_METADATA_MQH

input group "--- Registry Metadata ---";
input string InpEAVersion = "v1.0.0"; // EA version string for registry tagging

//+------------------------------------------------------------------+
//| Generates a short run unique ID from key identifying fields      |
//+------------------------------------------------------------------+
string GenerateRunUID(const string symbol,
                      const string tf_str,
                      const string indicator,
                      const int    period,
                      const string timestamp)
  {
   string raw = symbol + tf_str + indicator + IntegerToString(period) + timestamp;
   ulong  hash = 0;
   int    len  = StringLen(raw);

   for(int i = 0; i < len; i++)
      hash = (hash * 31 + (ulong)StringGetCharacter(raw, i)) % 99991UL;

   return(StringFormat("RUN%05d", (int)hash));
  }

//+------------------------------------------------------------------+
//| Returns the current UTC time as a formatted string               |
//+------------------------------------------------------------------+
string GetUTCTimestamp()
  {
   datetime utc_now = TimeGMT();
   return(TimeToString(utc_now, TIME_DATE | TIME_MINUTES | TIME_SECONDS));
  }

//+------------------------------------------------------------------+
//| Appends registry metadata columns to an existing CSV row string  |
//+------------------------------------------------------------------+
string AppendRegistryMetadata(const string base_row,
                              const string symbol,
                              const string tf_str,
                              const string indicator,
                              const int    period)
  {
   string ts  = GetUTCTimestamp();
   string uid = GenerateRunUID(symbol, tf_str, indicator, period, ts);
   return(base_row + "," + ts + "," + InpEAVersion + "," + uid);
  }

//+------------------------------------------------------------------+
//| Returns the three additional column header names                 |
//+------------------------------------------------------------------+
string GetRegistryMetadataHeader()
  {
   return("Run_Timestamp_UTC,EA_Version,Run_Unique_ID");
  }

#endif // REGISTRY_METADATA_MQH
//+------------------------------------------------------------------+