import 'package:get/get.dart';

///登录方式
enum SignInMethod {
  ///用户名密码登录
  Account,

  ///验证码登录
  VerificationCode,
}

///登录状态
class SignInState {
  final Rx<SignInMethod> _signInMethod = Rx(SignInMethod.Account);
  final Rx<bool> _onSubmit = Rx(false);
  final Rx<bool> _isAutoLogin = Rx(false);
  final Rx<bool> _isAgreeClause = Rx(false);
  final Rx<bool> _isForce = Rx(false);
  final Rx<String> _account = Rx('');
  final Rx<String> _password = Rx('');
  final Rx<String> _codeAccount = Rx('');
  final Rx<String> _verificationCode = Rx('');
  final Rx<double> _renderedHeight = Rx(0.0);
  final Rx<String> _userCode = Rx('');

  double get renderedHeight => _renderedHeight.value;
  set renderedHeight(double val) => _renderedHeight.value = val;

  /// 登录方式
  SignInMethod get signInMethod => _signInMethod.value;
  set signInMethod(SignInMethod val) => _signInMethod.value = val;

  /// 是否验证码登录
  bool get isCodeSignIn => signInMethod == SignInMethod.VerificationCode;

  /// 账号(手机/邮箱/用户名)
  String get account => _account.value;
  set account(String val) => _account(val);

  /// 密码
  String get password => _password.value;
  set password(String val) => _password(val);

  /// 账号(手机/邮箱)
  String get codeAccount => _codeAccount.value;
  set codeAccount(String val) => _codeAccount(val);

  /// 验证码
  String get verificationCode => _verificationCode.value;
  set verificationCode(String val) => _verificationCode(val);

  /// 正在提交
  bool get onSubmit => _onSubmit.value;
  set onSubmit(bool val) => _onSubmit.value = val;

  /// 是否记住密码
  bool get isAutoLogin => _isAutoLogin.value;
  set isAutoLogin(bool val) => _isAutoLogin.value = val;

  /// 是否同意条款和政策
  bool get isAgreeClause => _isAgreeClause.value;
  set isAgreeClause(bool val) => _isAgreeClause(val);

  /// 是否可提交
  bool get isCanSubmit {
    if (isCodeSignIn) {
      return codeAccount.isNotEmpty && verificationCode.isNotEmpty;
    }
    return account.isNotEmpty && password.isNotEmpty;
  }

  /// 是否强制更新
  bool get isForce => _isForce.value;
  set isForce(bool val) => _isForce(val);

  /// 用户code
  String get userCode => _userCode.value;
  set userCode(String val) => _userCode(val);
}
