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

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

  /**
   * 增加代理商
   * @param paramObject 参数
   * @param callBack
   */
  addAgent(paramObject: object, callBack) {
    this.http.post(environment.baseUrl + 'tyAgent/addAgent', paramObject).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 修改代理商
   * @param paramObject 参数
   * @param callBack
   */
  updateAgent(paramObject: object, callBack) {
    this.http.post(environment.baseUrl + 'tyAgent/updateAgent', paramObject).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 代理商密码重置
   * @param paramObject 参数
   * @param callBack
   */
  agentPwdReset(paramObject: object, callBack) {
    this.http.post(environment.baseUrl + 'tyAgent/agentPwdReset', paramObject).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 代理商密码重置
   * @param paramObject 参数
   * @param callBack
   */
  delAgent(paramObject: object, callBack) {
    this.http.post(environment.baseUrl + 'tyAgent/delAgent', paramObject).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 查询代理商详情
   * @param paramObject 参数
   * @param callBack
   */
  getDetailByKey(agentKey: string, callBack) {
    this.http.get(environment.baseUrl + 'tyAgent/getDetailByKey?key=' + agentKey).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 查询代理商列表
   * @param paramObject 参数
   * @param callBack
   */
  getAgentList(paramObject: object, callBack) {
    this.http.get(environment.baseUrl + 'tyAgent/getAgentList?' + this.common.getWhereCondition(paramObject)).subscribe(data => {
      callBack(data);
    });
  }

}
