package com.cloudhandson.ddsbackoffice.service;

import com.cloudhandson.ddsbackoffice.domain.DdsSqlEvidence;
import java.util.ArrayDeque;
import java.util.List;
import org.springframework.stereotype.Service;

/** Keeps a small, redacted in-memory audit trail for the console session. */
@Service
public class DdsSqlEvidenceHistory {
  private static final int MAX_ENTRIES = 20;
  private final ArrayDeque<DdsSqlEvidence> entries = new ArrayDeque<>();

  public synchronized void record(DdsSqlEvidence evidence) {
    if (evidence == null) return;
    entries.removeIf(entry -> entry.requestId().equals(evidence.requestId()));
    entries.addFirst(evidence);
    while (entries.size() > MAX_ENTRIES) entries.removeLast();
  }

  public synchronized List<DdsSqlEvidence> recent() {
    return List.copyOf(entries);
  }
}
