import { Injectable } from '@angular/core';
import { environments } from '../../../../environments/environments';
import { HttpClient, HttpHeaders } from '@angular/common/http';

@Injectable({
  providedIn: 'root'
})
export class PeriodosService {
  private URL: string = environments.baseUrl;

  constructor(private http: HttpClient) { }

  private getHeaders(): HttpHeaders {
    const token = localStorage.getItem('token') || '';
    return new HttpHeaders({
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${token}`
    });
  }

  crearPeriodo(periodo: any) {
    return this.http.post<any>(`${this.URL}/crearPeriodo`, periodo, { headers: this.getHeaders() });
  }

  getAllPeriodos() {
    return this.http.get<any[]>(`${this.URL}/getAllPeriodos`, { headers: this.getHeaders() });
  }

  activarPeriodo(id: string) {
    return this.http.post<any>(`${this.URL}/activarPeriodo`, { idPeriodo: id }, { headers: this.getHeaders() });
  }

  desactivarPeriodo(id: string) {
    return this.http.post<any>(`${this.URL}/deshabilitarPeriodo`, { idPeriodo: id }, { headers: this.getHeaders() });
  }

  habilitarPeriodo(id: string) {
    return this.http.post<any[]>(`${this.URL}/habilitarPeriodo`, { idPeriodo: id }, { headers: this.getHeaders() });
  }
}
