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

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

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


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

    /**
     * @Author Sum1Dream
     * @methodName editPriceStatus
     * @Description // 修改价格状态
     * @Date 15:03 2021/8/12
     * @Param mod
     **/
    public updateProduct(params: object, callBack) {
        this.http.post(environment.baseUrl + 'apiProduct/updateProduct', params).subscribe(data => {
            callBack(data);
        });
    }

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

    /**
     * @Author Sum1Dream
     * @methodName editPriceStatus
     * @Description // 修改价格状态
     * @Date 15:03 2021/8/12
     * @Param mod
     **/
    public editProductStatus(params: object, callBack) {
        this.http.post(environment.baseUrl + 'apiProduct/editProductStatus', params).subscribe(data => {
            callBack(data);
        });
    }

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

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

    public getListMerchProduct(id: number, callBack) {
        this.http.get(environment.baseUrl + 'apiMerchants/getListMerchProduct?merchantId=' + id).subscribe(data => {
            callBack(data);
        });
    }

}
