import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { CheckIn } from '../models/dashboard.model';  

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

  private apiUrl = 'http://localhost:8080/checkin'; 

  constructor(private http: HttpClient) { }

  saveCheckIn(checkInData: { idFuncionario: number, nivelHumor: number, comentario: string, dataHora: string }): Observable<void> {
    return this.http.post<void>(`${this.apiUrl}/novo`, checkInData);
  }

  obterMediaPorSetor(dataInicial: string | null, dataFinal: string | null): Observable<any> {
    return this.http.get(`${this.apiUrl}/media-por-setor`, {
      params: {
        dataInicial: dataInicial ?? '',
        dataFinal: dataFinal ?? ''
      }
    });
  }

  obterPercentualPorNota(dataInicial: string | null, dataFinal: string | null): Observable<any> {
    return this.http.get(`${this.apiUrl}/percentual-por-nota`, {
      params: {
        dataInicial: dataInicial ?? '',
        dataFinal: dataFinal ?? ''
      }
    });
  }

  obterPercentualNegativoPorSetor(dataInicial: string | null, dataFinal: string | null): Observable<any> {
    return this.http.get(`${this.apiUrl}/percentual-negativo-por-setor`, {
      params: {
        dataInicial: dataInicial ?? '',
        dataFinal: dataFinal ?? ''
      }
    });
  }

  obterPercentualRespondentesPorSetor(dataInicial: string | null, dataFinal: string | null): Observable<any> {
    return this.http.get(`${this.apiUrl}/percentual-respondentes-por-setor`, {
      params: {
        dataInicial: dataInicial ?? '',
        dataFinal: dataFinal ?? ''
      }
    });
  }
}
