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 GasClassGroupTaskService {

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

  /**
   * 开启班组任务
   *
   * @param  param   参数对象
   * @param  callBack   回调
   */
  public startGroupTask(param: object, callBack) {
    this.http.post(environment.baseUrl + 'gasClassGroupTask/startGroupTask', param).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 结束班组任务
   *
   * @param  param   参数对象
   * @param  callBack   回调
   */
  public endGroupTask(param: object, callBack) {
    this.http.post(environment.baseUrl + 'gasClassGroupTask/endGroupTask', param).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 交换班组任务
   *
   * @param  param   参数对象
   * @param  callBack   回调
   */
  public swapGroupTask(param: object, callBack) {
    this.http.post(environment.baseUrl + 'gasClassGroupTask/swapGroupTask', param).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 交换班组任务
   *
   * @param  param   参数对象
   * @param  callBack   回调
   */
  public getClassGroupTaskById(id: number, callBack) {
    this.http.get(environment.baseUrl + 'gasClassGroupTask/getClassGroupTaskById?gasClassGroupTaskId=' + id).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 交换班组任务
   *
   * @param  param   参数对象
   * @param  callBack   回调
   */
  public getCurrentClassGroupTask(gasId: number, callBack) {
    this.http.get(environment.baseUrl + 'gasClassGroupTask/getCurrentClassGroupTask?gasId=' + gasId).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 交换班组任务
   *
   * @param  param   参数对象
   * @param  callBack   回调
   */
  public getClassGroupTaskList(param: object, callBack) {
    this.http.get(environment.baseUrl + 'gasClassGroupTask/getClassGroupTaskList?' + this.common.getWhereCondition(param)).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 打印小票
   *
   * @param  param   参数对象
   * @param  callBack   回调
   */
  public print(gasClassGroupTaskId: number, callBack) {
    this.http.get(environment.baseUrl + 'gasClassGroupTask/print?gasClassGroupTaskId=' + gasClassGroupTaskId).subscribe(data => {
      callBack(data);
    });
  }

}
