import { HttpClient } from '@angular/common/http';
import { Injectable, inject } from '@angular/core';
import { Observable } from 'rxjs';
import { AuditEvent, SessionPermissions } from '../models/permission.model';
import { PermissionGateway } from './permission-gateway.interface';

/** Contract: docs/backend/TRACK-S-SECURITY-RBAC-CONTRACT.md §2-3. */
@Injectable({ providedIn: 'root' })
export class PermissionApiGateway implements PermissionGateway {
  private readonly http = inject(HttpClient);

  getSessionPermissions(): Observable<SessionPermissions> {
    return this.http.get<SessionPermissions>('/api/identity/v1/session/permissions');
  }

  loadAuditLog(): Observable<AuditEvent[]> {
    return this.http.get<AuditEvent[]>('/api/admin/v2/audit');
  }
}
