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

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

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

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

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

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


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

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

  /**
   * 根据公司 查询商户列表
   *
   * @param companyId  companyId
   * @param callBack 返回参数
   */
  public getMerchantListByCompany(companyId: number, callBack) {
    let id = null;
    if (companyId != null) {
      id = 'companyId=' + companyId;
    }
    this.http.get(environment.baseUrl + 'highMerchant/getMerchantListByCompany?' + id).subscribe(data => {
      callBack(data);
    });
  }


}
