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


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

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

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

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

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


  /**
   * 修改公司状态
   *
   * @param id  用户id
   * @param status  status
   * @param callBack 返回参数
   */
  public editStatus(id: number, status: number, callBack) {
    this.http.get(environment.baseUrl + 'discount/updateDiscountStatus?discountId=' + id + '&status=' + status ).subscribe(data => {
      callBack(data);
    });
  }


  /**
   * 增加优惠券和卡券关系
   *
   * @param params 上传对象
   * @param  callBack   回调
   * @return data 返回结果
   */
  public insertDiscountCoupon(params: object, callBack) {
    this.http.post(environment.baseUrl + 'discountCoupon/insertDiscountCoupon', params).subscribe(data => {
      callBack(data);
    });
  }


  /**
   * 根据优惠券 查询关联卡券
   *
   * @param id  用户id
   * @param callBack 返回参数
   */
  public getRelByDiscount(id: number, callBack) {
    this.http.get(environment.baseUrl + 'discountCoupon/getRelByDiscount?discountId=' + id ).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 代理商查询优惠券使用情况
   *
   * @param id  用户id
   * @param callBack 返回参数
   */
  public getDiscountUseConditionList(param: object, callBack) {
    this.http.get(environment.baseUrl + 'discountAgentRel/getDiscountUseConditionList?' + this.common.getWhereCondition(param)).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 删除
   *
   * @param id  用户id
   * @param callBack 返回参数
   */
  public delete(id: number, callBack) {
    this.http.get(environment.baseUrl + 'discountCoupon/delete?id=' + id ).subscribe(data => {
      callBack(data);
    });
  }
}
