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

@Injectable({
  providedIn: 'root'
})
export class RelacionarProfesoresService {
  private URL: string = environments.baseUrl;
  private dataUpdated = new Subject<void>();
  dataUpdated$ = this.dataUpdated.asObservable();
  constructor(private http: HttpClient) { }
  private getHeaders(): HttpHeaders {
    const token = localStorage.getItem('token') || '';
    return new HttpHeaders({
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${token}`
    });
  }

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

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

  RelacionarProfesor(data:any){
    return this.http.post(`${this.URL}/RelacionarProfesor`,data,{ headers: this.getHeaders() })
    .pipe(tap(() => this.dataUpdated.next()));
  }
  EliminarRelacion(data:any){
    return this.http.delete(`${this.URL}/eliminarRelacion`,{ headers: this.getHeaders(), params: data })
    .pipe(tap(() => this.dataUpdated.next()));
  }
}