import { apiService } from '../net/ApiService';
import { ToastUtils } from '../utils/ToastUtils';
import { BaseViewModel } from './BaseViewModel';

@ObservedV2
export class QrcodeLoginViewModel extends BaseViewModel {
  @Trace loginResult?: object

  async login(code: string) {
    this.showLoading()
    try {
      const result = await apiService.loginByCode(code);
      if (result.isSuccess()) {
        this.loginResult = new Object()
      } else {
        ToastUtils.show(result.message, true);
      }
      this.dismissLoading();
    } catch (e) {
      this.dismissLoading()
      console.debug(e)
      ToastUtils.show(e)
    }
  }
}