import { HttpClient } from '@angular/common/http';
import { Injectable, inject } from '@angular/core';
import { Observable } from 'rxjs';
import { environment } from '../../../environments/environment';
import { CreatePenalty, Penalty, UpdatePenalty } from '../../models/penalty.model';

@Injectable({ providedIn: 'root' })
export class PenaltyApi {
  private readonly http = inject(HttpClient);
  private readonly baseUrl = `${environment.apiUrl}penalty`;

  loadPenalties(teamId: number): Observable<Penalty[]> {
    return this.http.get<Penalty[]>(`${this.baseUrl}/${teamId}`);
  }

  createPenalty(penalty: CreatePenalty): Observable<Penalty> {
    return this.http.post<Penalty>(this.baseUrl, penalty);
  }

  updatePenalty(penaltyId: number, penalty: UpdatePenalty): Observable<Penalty> {
    return this.http.patch<Penalty>(`${this.baseUrl}/${penaltyId}`, penalty);
  }

  deletePenalty(penaltyId: number): Observable<void> {
    return this.http.delete<void>(`${this.baseUrl}/${penaltyId}`);
  }
}
