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

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

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

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

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

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

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

  /**
   * 增加代理商
   * @param paramObject 参数
   * @param callBack
   */
  queryAgent(agentId: number, callBack) {
    this.http.get(environment.baseUrl + 'agent/queryAgent?agentId=' + agentId).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 增加代理商
   * @param paramObject 参数
   * @param callBack
   */
  queryAgentList(paramObject: object, callBack) {
    this.http.get(environment.baseUrl + 'agent/queryAgentList?' + this.commonsService.getWhereCondition(paramObject)).subscribe(data => {
      callBack(data);
    });
  }

}
