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() {
    return this._httpRequestService.getQuery(`${this._url}`).pipe(
      map((data: any) => data));
  }

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

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

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

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

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

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

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

}
