import { Injectable } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
import { Observable } from 'rxjs';
import { ApiConfigService } from '../../../core/services/api-config.service';
import { FunctionalExpenseStatementDto } from '../models/form990-report.model';

@Injectable({ providedIn: 'root' })
export class Form990ReportApiService {
  private readonly endpoint: string;

  constructor(private http: HttpClient, apiConfig: ApiConfigService) {
    this.endpoint = apiConfig.getApiUrl('form990-report');
  }

  getFunctionalExpenses(from?: string, to?: string): Observable<FunctionalExpenseStatementDto> {
    let params = new HttpParams();
    if (from) { params = params.set('from', from); }
    if (to)   { params = params.set('to', to); }
    return this.http.get<FunctionalExpenseStatementDto>(
      `${this.endpoint}/functional-expenses`,
      { params }
    );
  }
}
