import { Injectable } from '@nestjs/common';
import { AuditLogRepository } from '../../infrastructure/repositories/audit-log.repository';
import { AuditLog } from '../../domain/entities/audit-log.entity';

@Injectable()
export class RecordAuditUseCase {
  constructor(private readonly auditRepo: AuditLogRepository) {}

  async execute(params: {
    tenantId: string;
    actionType: string;
    actorType: 'agent' | 'user' | 'system';
    actorId?: string;
    resourceType?: string;
    resourceId?: string;
    detail: Record<string, unknown>;
    ipAddress?: string;
  }): Promise<AuditLog> {
    const log = new AuditLog();
    Object.assign(log, params);
    return this.auditRepo.save(log);
  }
}
