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

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

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

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

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

  /**
   * 根据id查询详情
   *
   * @param  companyId   公司id
   * @param  callBack   回调
   */
  public companyView(companyId: number, callBack) {
    this.http.get(environment.baseUrl + 'bsCompany/companyView?companyId=' + companyId).subscribe(data => {
      callBack(data);
    });
  }


  /**
   * 修改公司状态
   *
   * @param id  用户id
   * @param status  status
   * @param callBack 返回参数
   */
  public editStatus(id: number, status: number , callBack) {
    this.http.get(environment.baseUrl + 'bsCompany/editStatus?companyId=' + id + '&status=' + status).subscribe(data => {
      callBack(data);
    });
  }


}
