import { Injectable, inject } from '@angular/core';
import { Observable } from 'rxjs';
import { ApiService } from '../../../core/services/api.service';
import {
  AuditLogDto,
  EntityAuditTrailDto,
  AuditMetadataDto,
  PaginatedAuditLogsResponse,
  AuditLogFilters,
} from '../../../api/models';

@Injectable({
  providedIn: 'root',
})
export class AuditService {
  private readonly api = inject(ApiService);

  getAuditLogs(filters?: AuditLogFilters): Observable<PaginatedAuditLogsResponse> {
    return this.api.get<PaginatedAuditLogsResponse>('/audit', filters as Record<string, string | number | boolean>);
  }

  getEntityTrail(entityType: string, entityId: string): Observable<EntityAuditTrailDto> {
    return this.api.get<EntityAuditTrailDto>(`/audit/entity/${entityType}/${entityId}`);
  }

  getAuditMetadata(): Observable<AuditMetadataDto> {
    return this.api.get<AuditMetadataDto>('/audit/metadata');
  }
}
