import json

STATE_FILE = "backtest_state.json"
SHADOW_FILE = "data/shadow-trades.json"

def fix():
    try:
        with open(STATE_FILE, 'r') as f:
            state = json.load(f)
            
        state["next_cursor_date"] = "2026-01-07 15:30:00"
        state["completed_through"] = "2026-01-07 05:30:00 UTC (13:30 WITA approx)"
        state["progress_notes"].append("Batch completed: Shadow trade hit target (4452.395 vs 4460.00 TP). +1.43R captured in shadow analysis on Bearish FVG Retracement setup.")
        
        with open(STATE_FILE, 'w') as f:
            json.dump(state, f, indent=2)
            
    except Exception as e:
        print(f"Error state: {e}")

    try:
        with open(SHADOW_FILE, 'r') as f:
            shadows = json.load(f)
            
        # Update last shadow trade
        if len(shadows) > 0:
            shadows[-1]["outcome"] = "win"
            shadows[-1]["pnl_r"] = 1.43
            shadows[-1]["notes"] += " Target 4460 hit on the 13:30 WITA bar (low 4448.685)."
            
        with open(SHADOW_FILE, 'w') as f:
            json.dump(shadows, f, indent=2)
            
    except Exception as e:
        print(f"Error shadow: {e}")

if __name__ == "__main__":
    fix()
