import { Injectable } from '@angular/core';
import {HttpClient} from "@angular/common/http";
import {environment} from "../../../environments/environment";
import {ObjectData} from "../../utils/objectData.service";

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

  constructor(private http: HttpClient) { }

  /**
   *
   * 编辑账户
   * @param params
   * @param callBack
   */
  public editUser(params: any, callBack:any) {
    params.time = new Date().getTime();
    this.http.post(environment.baseUrl + 'secUser/editUser', params).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 删除账户
   * @param params
   * @param callBack
   */
  public delete(params: any, callBack:any) {
    params.time = new Date().getTime();
    this.http.post(environment.baseUrl + 'secUser/delete', params).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 恢复账户
   * @param params
   * @param callBack
   */
  public restore(params: any, callBack:any) {
    params.time = new Date().getTime();
    this.http.post(environment.baseUrl + 'secUser/restore', params).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 禁用账户
   * @param params
   * @param callBack
   */
  public disable(params: any, callBack:any) {
    params.time = new Date().getTime();
    this.http.post(environment.baseUrl + 'secUser/disable', params).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 密码重置
   * @param userId
   * @param callBack
   */
  public resetPwd(param: any, callBack:any) {
    param.time = new Date().getTime();
    this.http.post(environment.baseUrl + 'secUser/resetPwd', param).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 查询详情
   * @param userId
   * @param callBack
   */
  public queryDetail(userId: number, callBack:any) {
    let params = {
      userId: userId,
      time: new Date().getTime()
    };
    this.http.get(environment.baseUrl + 'secUser/queryDetail?'+ObjectData.objectByString(params)).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 查询列表
   * @param params
   * @param callBack
   */
  public queryList(params: any, callBack:any) {
    params.time = new Date().getTime();
    this.http.get(environment.baseUrl + 'secUser/queryList?'+ObjectData.objectByString(params)).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 查询账户登录列表
   * @param params
   * @param callBack
   */
  public queryLoginLogList(params: any, callBack:any) {
    params.time = new Date().getTime();
    this.http.get(environment.baseUrl + 'secUser/queryLoginLogList?'+ObjectData.objectByString(params)).subscribe(data => {
      callBack(data);
    });
  }



}
