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

import { environments } from '../../../../environments/environments';
import { NivelEducativo } from '../interfaces/NivelEducativo.interface';
import { filter, map } from 'rxjs';

@Injectable({
  providedIn: 'root'
})
export class NivelEducativoService {
  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}`
    });
  }

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

  getHabilitados() {
    return this.http.get(`${this.URL}/nivelEducativoHabilitado`, { headers: this.getHeaders() });
  }

  getOne(id: string) {
    let qId = btoa(id);
    return this.http.get(`${this.URL}/nivelEducativoOne/${qId}`, { headers: this.getHeaders() });
  }


  actualizarNivel(data: any) {
    return this.http.put(`${this.URL}/nivelEducativoE`, data, { headers: this.getHeaders() });
  }

  crearNivel(nivel: NivelEducativo) {
    return this.http.post(`${this.URL}/nivelEducativoSave`, nivel, { headers: this.getHeaders() });
  }

  eliminarNivel(id: string) {
    let qId = btoa(id);
    return this.http.put(`${this.URL}/nivelEducativoDelete/${qId}`, null, { headers: this.getHeaders() });
  }

  habilitarNivel(id: string) {
    let qId = btoa(id);
    return this.http.put(`${this.URL}/nivelEducativoEnable/${qId}`, null, { headers: this.getHeaders() });
  }
}
