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

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

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

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

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

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

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

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

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


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

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