import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { ApiConfigService } from '../../../core/services/api-config.service';
import {
  ExpenseSnapshotDto, CreateExpenseSnapshotRequest, UpdateExpenseSnapshotRequest,
} from '../models/expense-snapshot.model';

@Injectable({ providedIn: 'root' })
export class ExpenseSnapshotApiService {
  private readonly endpoint: string;
  constructor(private http: HttpClient, apiConfig: ApiConfigService) {
    this.endpoint = apiConfig.getApiUrl('expense-snapshots');
  }
  getAll(): Observable<ExpenseSnapshotDto[]> {
    return this.http.get<ExpenseSnapshotDto[]>(this.endpoint);
  }
  getById(id: number): Observable<ExpenseSnapshotDto> {
    return this.http.get<ExpenseSnapshotDto>(`${this.endpoint}/${id}`);
  }
  create(r: CreateExpenseSnapshotRequest): Observable<{ id: number }> {
    return this.http.post<{ id: number }>(this.endpoint, r);
  }
  update(id: number, r: UpdateExpenseSnapshotRequest): Observable<void> {
    return this.http.put<void>(`${this.endpoint}/${id}`, r);
  }
  delete(id: number): Observable<void> {
    return this.http.delete<void>(`${this.endpoint}/${id}`);
  }
}
