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

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

  loadTeam(token: string): Observable<PublicTeamOverview> {
    return this.http.get<PublicTeamOverview>(
      `${environment.apiUrl}public/teams/${encodeURIComponent(token)}`,
    );
  }

  loadPlayerHistory(token: string, playerId: number): Observable<PublicPlayerHistory> {
    return this.http.get<PublicPlayerHistory>(
      `${environment.apiUrl}public/teams/${encodeURIComponent(token)}/players/${playerId}/transactions`,
    );
  }
}
