"""
generate_test_exports.py
Creates multi‑row synthetic broker CSV exports for testing the
broker_normalizer.py module. Each broker gets 10 rows with distinct
Avg_Slippage_Points values to produce realistic KDE plots.
"""

import pandas as pd
import os
import numpy as np

os.makedirs("exports", exist_ok=True)

# --- BrokerA: 10 rows, varying slippage around 1.2 ---------------------------
n = 10
np.random.seed(42)
df_a = pd.DataFrame({
    "Test_Phase"            : ["Baseline"] * n,
    "Symbol"                : ["EURUSD"] * n,
    "Timeframe"             : ["H1"] * n,
    "Indicator_Name"        : ["EMA_Crossover"] * n,
    "Filter_Period"         : [14] * n,
    "Net_Profit"            : [500.0] * n,
    "Sortino_Ratio"         : [1.5] * n,
    "Max_Drawdown_PCT"      : [12.0] * n,
    "False_Flips_Whipsaws"  : [5] * n,
    "Avg_Lag_On_Turn_Bars"  : [2.3] * n,
    "Total_Trades"          : [10] * n,
    "Broker_Server"         : ["BrokerA-ECN"] * n,
    "Account_Currency"      : ["USD"] * n,
    "Symbol_Digits"         : [5] * n,
    "Commission_Per_Lot"    : [3.50] * n,
    "Total_Commission_Paid" : [35.0] * n,
    "Avg_Slippage_Points"   : np.round(np.random.normal(1.2, 0.3, n), 2),
    "Gross_Profit"          : [535.0] * n,
    "Open_Time"             : ["2026-01-15 08:00:00"] * n    # UTC+2
})
df_a.to_csv("exports/brokerA_results.csv", index=False)

# --- BrokerB: 10 rows, varying slippage around 0.8 ---------------------------
df_b = pd.DataFrame({
    "Test_Phase"            : ["Baseline"] * n,
    "Symbol"                : ["EURUSDm"] * n,
    "Timeframe"             : ["H1"] * n,
    "Indicator_Name"        : ["EMA_Crossover"] * n,
    "Filter_Period"         : [14] * n,
    "Net_Profit"            : [400.0] * n,
    "Sortino_Ratio"         : [1.2] * n,
    "Max_Drawdown_PCT"      : [15.0] * n,
    "False_Flips_Whipsaws"  : [3] * n,
    "Avg_Lag_On_Turn_Bars"  : [1.8] * n,
    "Total_Trades"          : [8] * n,
    "Broker_Server"         : ["BrokerB-MM"] * n,
    "Account_Currency"      : ["EUR"] * n,
    "Symbol_Digits"         : [5] * n,
    "Commission_Per_Lot"    : [0.0] * n,
    "Total_Commission_Paid" : [0.0] * n,
    "Avg_Slippage_Points"   : np.round(np.random.normal(0.8, 0.25, n), 2),
    "Gross_Profit"          : [400.0] * n,
    "Open_Time"             : ["2026-01-15 08:00:00"] * n    # UTC+3
})
df_b.to_csv("exports/brokerB_results.csv", index=False)

# --- BrokerC: 10 rows, 4‑digit → slippage will be scaled x10 later -----------
df_c = pd.DataFrame({
    "Test_Phase"            : ["Baseline"] * n,
    "Symbol"                : ["Dow Jones"] * n,
    "Timeframe"             : ["H1"] * n,
    "Indicator_Name"        : ["EMA_Crossover"] * n,
    "Filter_Period"         : [14] * n,
    "Net_Profit"            : [300.0] * n,
    "Sortino_Ratio"         : [1.0] * n,
    "Max_Drawdown_PCT"      : [20.0] * n,
    "False_Flips_Whipsaws"  : [8] * n,
    "Avg_Lag_On_Turn_Bars"  : [2.7] * n,
    "Total_Trades"          : [6] * n,
    "Broker_Server"         : ["BrokerC-STP"] * n,
    "Account_Currency"      : ["GBP"] * n,
    "Symbol_Digits"         : [4] * n,
    "Commission_Per_Lot"    : [5.00] * n,
    "Total_Commission_Paid" : [30.0] * n,
    "Avg_Slippage_Points"   : np.round(np.random.normal(2.0, 0.4, n), 2),
    "Gross_Profit"          : [330.0] * n,
    "Open_Time"             : ["2026-01-15 06:00:00"] * n    # UTC+0
})
df_c.to_csv("exports/brokerC_results.csv", index=False)

print("[Generator] Synthetic broker exports with 10 rows each created in 'exports/'.")