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

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

  constructor(
    private http: HttpClient,
    ) {
  }

  /**
   * 后台登录
   *
   * @param params 上传对象
   * @param  callBack   回调
   * @return data 返回结果
   */
  public userLogin(params: object, callBack) {
    this.http.post(environment.baseUrl + 'login/userLogin', params).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 后台登出
   *
   * @param  callBack   回调
   * @return data 返回结果
   */
  public loginOut(callBack) {
    this.http.post(environment.baseUrl + 'login/logout', null).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 获取验证码
   * @param  phone   传入电话
   * @param  callback   回调
   */
  public sendVerificationCode(phone , callback) {
    this.http.post(environment.baseUrl + 'sms/sendVerificationCode?phone=' + phone , null).subscribe(data => {
      callback(data);
    });
  }

  /**
   * 用户登录注册
   *
   * @param params 上传对象
   * @param  callBack   回调
   * @return data 返回结果
   */
  public registerUser(params: object, callBack) {
    this.http.post(environment.baseUrl + 'register/registerUser', params).subscribe(data => {
      callBack(data);
    });
  }



}
