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

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

  /**
   * 配置优惠活动
   * @param paramObject 参数
   * @param callBack
   */
  configActivity(paramObject: object, callBack) {
    this.http.post(environment.baseUrl + 'storeDiscountActivity/configActivity', paramObject).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 配置优惠活动
   * @param paramObject 参数
   * @param callBack
   */
  getActivityDetail(activityId: number, callBack) {
    this.http.get(environment.baseUrl + 'storeDiscountActivity/getActivityDetail?activityId=' + activityId).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 活动上线
   * @param paramObject 参数
   * @param callBack
   */
  upOnline(activityId: number, callBack) {
    this.http.get(environment.baseUrl + 'storeDiscountActivity/upOnline?activityId=' + activityId).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 活动下线
   * @param paramObject 参数
   * @param callBack
   */
  lowerOnline(activityId: number, callBack) {
    this.http.get(environment.baseUrl + 'storeDiscountActivity/lowerOnline?activityId=' + activityId).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 删除
   * @param paramObject 参数
   * @param callBack
   */
  delete(activityId: number, callBack) {
    this.http.get(environment.baseUrl + 'storeDiscountActivity/delete?activityId=' + activityId).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 查询优惠活动列表
   * @param paramObject 参数
   * @param callBack
   */
  getActivityList(paramObject: object,  callBack) {
    this.http.get(environment.baseUrl + 'storeDiscountActivity/getActivityList?' + this.commonsService.getWhereCondition(paramObject)).subscribe(data => {
      callBack(data);
    });
  }
}
