import { Injectable } from '@nestjs/common';
import { TaskActivityAuditRecord, TaskActivityAuditStore } from './task_activity_audit.store';

@Injectable()
export class TaskActivityAuditMemoryService implements TaskActivityAuditStore {
  private readonly records: Array<TaskActivityAuditRecord & { created_at: Date }> = [];
  private static readonly MAX_RECORDS = 5000;

  async append(record: TaskActivityAuditRecord): Promise<void> {
    this.records.push({ ...record, created_at: new Date() });
    if (this.records.length > TaskActivityAuditMemoryService.MAX_RECORDS) {
      this.records.splice(0, this.records.length - TaskActivityAuditMemoryService.MAX_RECORDS);
    }
  }
}
