import { Injectable } from '@angular/core';
import { map } from 'rxjs';
import { UpdatedStatusWorkteam, Workteam } from 'src/app/interfaces/personal-managment/workteam.interface';
import { HttpRequestService } from '../resources/http-request.service';

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

  private _url: string;
  constructor(private _httpRequestService: HttpRequestService) {
    this._url = 'workteam';
  }

  public getConsultOfWorkteams(idUser: string) {
    return this._httpRequestService.getQueryQA(`${this._url}/consult/${idUser}`).pipe(
      map((data: any) => data));
  }

  public getActiveWorkteams() {
    return this._httpRequestService.getQueryQA(`${this._url}/active-teams`).pipe(
      map((data: any) => data));
  }

  public getWorkteamById(workteamId: string, idUser: string) {
    return this._httpRequestService.getQueryQA(`${this._url}/only/${workteamId}/${idUser}`).pipe(
      map((data: any) => data));
  }

  public getDetailsOfWorkteamById(workteamId: string) {
    return this._httpRequestService.getQueryQA(`${this._url}/details/${workteamId}`).pipe(
      map((data: any) => data));
  }

  public getMembersOfWorkteamById(workteamId: string, idUser: string) {
    return this._httpRequestService.getQueryQA(`${this._url}/members/${workteamId}/${idUser}`).pipe(
      map((data: any) => data));
  }

  public updateToInactiveStatus(response: UpdatedStatusWorkteam) {
    return this._httpRequestService.postQueryQA(`${this._url}/delete`, response)
      .pipe(map((data: any) => data));
  }

  public updateToActiveStatus(response: UpdatedStatusWorkteam) {
    return this._httpRequestService.putQueryQA(`${this._url}/active-workteam/${response.WORKTEAM_ID}`, response)
      .pipe(map((data: any) => data));
  }

  public storeWorkteam(response: Workteam) {
    return this._httpRequestService.postQueryQA(`${this._url}/register`, response)
      .pipe(map((data: any) => data));
  }

  public updateWorkteam(response: Workteam) {
    return this._httpRequestService.postQueryQA(`${this._url}/update`, response)
      .pipe(map((data: any) => data));
  }

}
