import { inject, Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { TransactionData } from '../model/TransactionData';

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

  public getUsersTransactions(limit: number | null = null, offset: number | null = null) {
    const baseUrl = new URL(`${window.location.origin}/backend/user/transactions`);

    if (limit !== null) {
      baseUrl.searchParams.append('limit', limit.toString());
    }

    if (offset !== null) {
      baseUrl.searchParams.append('offset', offset.toString());
    }

    return this.http.get<TransactionData>(`${baseUrl}`);
  }
}
