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

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

  /**
   * 余额充值
   *
   * @param  paramsObject   参数对象
   * @param  callBack   回调
   */
  public recharge(paramsObject: object, callBack) {
    this.http.post(environment.baseUrl + 'companyAccount/recharge', paramsObject).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 查询余额
   *
   * @param  callBack   回调
   */
  public getAccount( callBack) {
    this.http.get(environment.baseUrl + 'companyAccount/getAccount').subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 发送充值短信验证码
   *
   * @param  phone  手机号
   * @param  callBack   回调
   */
  public sendRechargeSmsCode(phone: string, orgId: number, price: string, callBack) {
    this.http.get(environment.baseUrl + 'sendSms/sendRechargeSmsCode?phone=' + phone + '&orgId=' + orgId + '&price=' + price).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 查询余额记录列表
   *
   * @param  paramsObject  参数对象
   * @param  callBack   回调
   */
  public getAmountRecordList(paramsObject: object, callBack) {
    this.http.get(environment.baseUrl + 'companyAccount/getAccountRecordList?' + this.common.getWhereCondition(paramsObject)).subscribe(data => {
      callBack(data);
    });
  }
}
