import { Injectable } from "@angular/core";
import { HttpClient } from "@angular/common/http";
import { CachingService } from "../clients/caching.service";

@Injectable({ providedIn: "root" })
export class RobotService extends CachingService {
  constructor(private readonly http: HttpClient) {
    super("robots");
  }

  public getRobots(filters = {}) {
    this.request(
      this.http.get<any>("/api/robots", { params: filters })
    );
    return this.getStream();
  }

  public getRobotById(id: number) {
    this.request(this.http.get<any>(`/api/robots/${id}`));
    return this.getStream(id);
  }

  public updateRobot(robotInfo) {
    const { id } = robotInfo;

    this.request(this.http.put(`/api/robots/${id}`, robotInfo));
    return this.getStream(id);
  }
}
