import { HttpClient } from '@angular/common/http';
import { Injectable, inject } from '@angular/core';
import { Observable } from 'rxjs';
import { environment } from '../../../environments/environment';
import {
  CreatePlayerTransaction,
  CreateTeamWalletTransaction,
  TeamActivity,
} from '../../models/transaction.model';

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

  loadTeamTransactions(teamId: number): Observable<TeamActivity[]> {
    return this.http.get<TeamActivity[]>(`${environment.apiUrl}teams/${teamId}/transactions`);
  }

  createPlayerTransactions(transactions: CreatePlayerTransaction[]): Observable<TeamActivity[]> {
    return this.http.post<TeamActivity[]>(`${environment.apiUrl}transactions`, transactions);
  }

  createTeamWalletTransaction(transaction: CreateTeamWalletTransaction): Observable<TeamActivity> {
    return this.http.post<TeamActivity>(
      `${environment.apiUrl}team-wallet-transactions`,
      transaction,
    );
  }

  reverseTransaction(transactionId: number): Observable<TeamActivity> {
    return this.http.post<TeamActivity>(
      `${environment.apiUrl}transactions/${transactionId}/reverse`,
      {},
    );
  }
}
