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 CouponService {
  constructor(
      private http: HttpClient,
      private common: CommonsService
  ) { }

  /**
   * 查询卡券列表
   *
   * @param  paramsObject   对象
   * @param  callBack   回调
   */
  public getCouponList(paramsObject: object, callBack) {
    this.http.get(environment.baseUrl + 'coupon/getCouponList?' + this.common.getWhereCondition(paramsObject)).subscribe(data => {
      callBack(data);
    });
  }

    /**
     * 查询所有卡券列表
     *
     * @param  paramsObject   对象
     * @param  callBack   回调
     */
    public getCouponListByAll(paramsObject: object, callBack) {
        this.http.get(environment.baseUrl + 'coupon/getCouponListByAll?' + this.common.getWhereCondition(paramsObject)).subscribe(data => {
            callBack(data);
        });
    }

  /**
   * 查询卡券消费码列表
   *
   * @param  paramsObject   对象
   * @param  callBack   回调
   */
  public getCouponCodeList(paramsObject: object, callBack) {
    this.http.get(environment.baseUrl + 'couponCode/getCouponCodeList?' + this.common.getWhereCondition(paramsObject)).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 新增卡券
   *
   * @param params 上传对象
   * @param  callBack   回调
   * @return data 返回结果
   */
  public insertCoupon(params: object, callBack) {
    this.http.post(environment.baseUrl + 'coupon/insertCoupon', params).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 修改卡券
   *
   * @param params 上传对象
   * @param  callBack   回调
   * @return data 返回结果
   */
  public updateCoupon(params: object, callBack) {
    this.http.post(environment.baseUrl + 'coupon/updateCoupon', params).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 根据id查询详情
   *
   * @param  couponId   卡券id
   * @param  callBack   回调
   */
  public getCouponById(couponId: number, callBack) {
    this.http.get(environment.baseUrl + 'coupon/getCouponById?id=' + couponId).subscribe(data => {
      callBack(data);
    });
  }


  /**
   * 下架卡券
   *
   * @param id  用户id
   * @param callBack 返回参数
   */
  public ofShelfApprove(id: number, callBack) {
    this.http.get(environment.baseUrl + 'coupon/ofShelfApprove?id=' + id).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 上架卡券
   *
   * @param id  用户id
   * @param callBack 返回参数
   */
  public upShelfApprove(id: number, callBack) {
    this.http.get(environment.baseUrl + 'coupon/upShelfApprove?id=' + id).subscribe(data => {
      callBack(data);
    });
  }


  public getGuizhouSinopec( callBack) {
    this.http.get(environment.baseUrl + 'coupon/getGuizhouSinopec?merchantId=40').subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 生成消费码
   *
   * @param params 上传对象
   * @param  callBack   回调
   * @return data 返回结果
   */
  public writeStock(params: object, callBack) {
    this.http.post(environment.baseUrl + 'coupon/writeStock', params).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 导出销售码
   *
   * @param params 上传对象
   * @param  callBack   回调
   * @return data 返回结果
   */
  public exportStock(params: object, callBack) {
    this.http.post(environment.baseUrl + 'coupon/exportStock', params).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 查询贵州中石化分配列表
   *
   * @param id  用户id
   * @param callBack 返回参数
   */
  public getGzSinopecAssignList(params: object,  callBack) {
    this.http.get(environment.baseUrl + 'couponCode/getGzSinopecAssignList?' + this.common.getWhereCondition(params)).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 导出贵州中石化分配列表
   *
   * @param id  用户id
   * @param callBack 返回参数
   */
  public importGzSinopecAssign(params: object,  callBack) {
    this.http.get(environment.baseUrl + 'couponCode/importGzSinopecAssign?' + this.common.getWhereCondition(params)).subscribe(data => {
      callBack(data);
    });
  }

}
