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

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

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

  getTareas(idAlumno: string) {
    return this.http.get(`${this.URL}/tareas/usuario/${idAlumno}`, { headers: this.getHeaders() });
  }

  getByFechaEntrega(fechaEntrega: string, idUsuario: string) {
    return this.http.get(`${this.URL}/tareas/fecha-entrega/${fechaEntrega}/${idUsuario}`, { headers: this.getHeaders() });
  }

  getByFechaAsignacion(fechaAsignacion: string, idUsuario: string) {
    return this.http.get(`${this.URL}/tareas/fecha-asignacion/${fechaAsignacion}/${idUsuario}`, { headers: this.getHeaders() });
  }

  getByMateria(idMateria: string) {
    return this.http.get(`${this.URL}/tareas/materia/${idMateria}`, { headers: this.getHeaders() });
  }

  getMaterias30Dias(userId: string) {
    return this.http.get(`${this.URL}/tareas/materiaUlt30/${userId}`, { headers: this.getHeaders() });
  }


}
