import { Injectable } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
import { Observable, map } from 'rxjs';
import { bilingual } from '../../../shared/i18n/bilingual';
import { ApiConfigService } from '../../../core/services/api-config.service';
import { MinistryDto } from '../models/expense.model';

@Injectable({ providedIn: 'root' })
export class MinistryApiService {
  private readonly endpoint: string;
  constructor(private http: HttpClient, apiConfig: ApiConfigService) {
    this.endpoint = apiConfig.getApiUrl('ministries');
  }
  getAll(includeInactive = false): Observable<MinistryDto[]> {
    return this.http.get<MinistryDto[]>(this.endpoint, { params: new HttpParams().set('includeInactive', includeInactive) }).pipe(
      map(list => list.map(m => ({ ...m, label: bilingual(m.name_en, m.name_zh) }))),
    );
  }
}
