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

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

  /**
   * 交易抽成配置
   * @param paramObject 参数
   * @param callBack
   */
  editParentCompanyConfig(paramObject: object, callBack) {
    this.http.post(environment.baseUrl + 'tradeTakeConfig/editParentCompanyConfig', paramObject).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 交易抽成配置
   * @param paramObject 参数
   * @param callBack
   */
  editAgentConfig(paramObject: object, callBack) {
    this.http.post(environment.baseUrl + 'tradeTakeConfig/editAgentConfig', paramObject).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 查询交易配置
   * @param paramObject 参数
   * @param callBack
   */
  getTradeTakeConfig(companyId: number, platformType: number, profitSharingReceiverRole: number, receiverObjectId: number, subReceiverObjectId: number, callBack) {
    const param = {
      companyId: companyId,
      platformType: platformType,
      profitSharingReceiverRole: profitSharingReceiverRole,
      receiverObjectId: receiverObjectId,
      subReceiverObjectId: subReceiverObjectId,
    };

    this.http.get(environment.baseUrl + 'tradeTakeConfig/getTradeTakeConfig?' + this.commonsService.getWhereCondition(param)).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 查询代理商交易配置
   * @param paramObject 参数
   * @param callBack
   */
  getAgentTradeTakeConfig(platformType: number, agentId: number, callBack) {
    this.http.get(environment.baseUrl + 'tradeTakeConfig/getAgentTradeTakeConfig?platformType=' + platformType + '&agentId=' + agentId).subscribe(data => {
      callBack(data);
    });
  }

}
