import { Injectable, inject } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
import { Observable } from 'rxjs';
import { environment } from '../../../environments/environment';

@Injectable({ providedIn: 'root' })
export class FiscalPeriodService {
  private http = inject(HttpClient);
  private baseUrl = `${environment.apiUrl}/accounting/fiscal-periods`;

  list(page = 1, perPage = 100): Observable<any> {
    const params = new HttpParams().set('page', page).set('per_page', perPage);
    return this.http.get<any>(this.baseUrl, { params });
  }

  getById(periodId: number): Observable<any> {
    return this.http.get<any>(`${this.baseUrl}/${periodId}`);
  }

  close(periodId: number): Observable<any> {
    return this.http.post(`${this.baseUrl}/${periodId}/close`, {});
  }
}
