import { Injectable } from '@angular/core';
import { map } from 'rxjs';
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}/1`).pipe(
      map((data: any) => data));
  }

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

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

  public getDetailsOfWorkteamById(workteamId: number) {
    return this._httpRequestService.getQuery(`${this._url}/details/${workteamId}/1`).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 storeSubcontratist(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));
  }

}

export interface UpdatedStatusWorkteam {
  WORKTEAM_ID: number;
  SAVED_BY_USER: number;
  LINE_NUMBER: number;
}

export interface Workteam {
  WORKTEAM_ID?: number;
  NAME: string,
  SPECIALITY: string,
  SAVED_BY_USER: number,
  LINE_NUMBER: number
}