import { Injectable } from '@angular/core';
import { environments } from '../../../../environments/environments';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Grupo } from '../pages/Relacionar/alumnos-padres/alumnos-padres.component';
import { map } from 'rxjs';

@Injectable({
  providedIn: 'root'
})
export class GruposService {

  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}`
    });
  }

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

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

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


  actualizarGrupo(data: any) {

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

  crearGrupo(grupo: any) {
    return this.http.post(`${this.URL}/grupoSave`, grupo, { headers: this.getHeaders() });
  }

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

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