import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { Cronograma } from '../models/cronograma.model';

@Injectable({
  providedIn: 'root'
})
export class CronogramaService {
  private apiUrl = 'api/cronogramas';

  constructor(private http: HttpClient) {}

  getCronogramas(): Observable<Cronograma[]> {
    return this.http.get<Cronograma[]>(this.apiUrl);
  }

  getCronogramaById(id: number): Observable<Cronograma> {
    return this.http.get<Cronograma>(`${this.apiUrl}/${id}`);
  }

  createCronograma(cronograma: Cronograma): Observable<Cronograma> {
    return this.http.post<Cronograma>(this.apiUrl, cronograma);
  }

  updateCronograma(cronograma: Cronograma): Observable<Cronograma> {
    return this.http.put<Cronograma>(`${this.apiUrl}/${cronograma.id}`, cronograma);
  }

  deleteCronograma(id: number): Observable<void> {
    return this.http.delete<void>(`${this.apiUrl}/${id}`);
  }
}
