import { HttpClient } from '@angular/common/http';
import { Injectable, inject } from '@angular/core';
import { Observable } from 'rxjs';
import { environment } from '../../../environments/environment';
import { TeamPermissions, UpdateTeamPermissions } from '../../models/team-permissions.model';

@Injectable({ providedIn: 'root' })
export class TeamPermissionsApi {
  private readonly http = inject(HttpClient);

  getPermissions(teamId: number): Observable<TeamPermissions> {
    return this.http.get<TeamPermissions>(`${environment.apiUrl}teams/${teamId}/permissions`);
  }

  updatePermissions(
    teamId: number,
    changes: UpdateTeamPermissions,
  ): Observable<TeamPermissions> {
    return this.http.patch<TeamPermissions>(
      `${environment.apiUrl}teams/${teamId}/permissions`,
      changes,
    );
  }
}
