import { Injectable, inject, signal } from '@angular/core';
import { take } from 'rxjs/operators';
import { AuditEvent } from '../../../../core/permissions/models/permission.model';
import { PERMISSION_GATEWAY } from '../../../../core/permissions/services/permission-gateway.token';

@Injectable({ providedIn: 'root' })
export class AdminAuditFacade {
  private readonly gateway = inject(PERMISSION_GATEWAY);

  readonly events = signal<AuditEvent[]>([]);
  readonly loading = signal(false);

  load(): void {
    this.loading.set(true);
    this.gateway.loadAuditLog().pipe(take(1)).subscribe(items => {
      this.events.set(items);
      this.loading.set(false);
    });
  }
}
