import { HttpClient } from '@angular/common/http';
import { Injectable, inject } from '@angular/core';
import { Observable } from 'rxjs';
import { environment } from '../../../environments/environment';
import { PublicAccessStatus } from '../../models/public-access.model';

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

  getStatus(teamId: number): Observable<PublicAccessStatus> {
    return this.http.get<PublicAccessStatus>(`${environment.apiUrl}teams/${teamId}/public-access`);
  }

  setEnabled(teamId: number, enabled: boolean): Observable<PublicAccessStatus> {
    return this.http.patch<PublicAccessStatus>(
      `${environment.apiUrl}teams/${teamId}/public-access`,
      { enabled },
    );
  }

  rotate(teamId: number): Observable<PublicAccessStatus> {
    return this.http.post<PublicAccessStatus>(
      `${environment.apiUrl}teams/${teamId}/public-access/rotate`,
      {},
    );
  }
}
