import { Injectable } from '@angular/core';
import {HttpClient} from  '@angular/common/http';
import {CommonsService} from './commons.service';
import {environment} from '../../environments/environment';

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

  constructor(
      private http: HttpClient,
      private common: CommonsService
  ) { }


  /**
   * 编辑设备
   *
   * @param  paramsObject   对象
   * @param  callBack   回调
   */
  public editDevice(paramsObject: object, callBack) {
    this.http.post(environment.baseUrl + 'device/editDevice', paramsObject).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 删除设备
   *
   * @param  id   设备id
   * @param  callBack   回调
   */
  public delDevice(id: number, callBack) {
    this.http.post(environment.baseUrl + 'device/delDevice', { deviceId: id}).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 查询设备详情
   *
   * @param  id   设备id
   * @param  callBack   回调
   */
  public getDetailById(id: number, callBack) {
    this.http.get(environment.baseUrl + 'device/getDetailById?deviceId=' + id).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 查询设备列表
   *
   * @param  id   设备id
   * @param  callBack   回调
   */
  public getDeviceList(param: object, callBack) {
    this.http.get(environment.baseUrl + 'device/getDeviceList?' + this.common.getWhereCondition(param)).subscribe(data => {
      callBack(data);
    });
  }

}
