export interface MemoryRecord {
  id: string;
  symbol: string;
  tradeSignal: { positionSize: number; stopLoss: number };
  result: { pnl: number; isWin: boolean; fee: number };
  timestamp: number;
}

export class MemorySystem {
  records: MemoryRecord[] = [];

  addRecord(record: MemoryRecord) {
    this.records.push(record);
  }

  getRecentWinRate(symbol: string, limit: number = 10): number {
    const relevant = this.records.filter(r => r.symbol === symbol).slice(-limit);
    if (relevant.length === 0) return 0.5;
    const wins = relevant.filter(r => r.result.isWin).length;
    return wins / relevant.length;
  }

  getFailureRate(symbol: string, limit: number = 5): number {
    const relevant = this.records.filter(r => r.symbol === symbol).slice(-limit);
    if (relevant.length < 3) return 0; // Not enough data to judge
    const losses = relevant.filter(r => !r.result.isWin).length;
    return losses / relevant.length;
  }

  getMemorySize(): number {
    return this.records.length;
  }
}
