import 'package:fis_i18n/i18n.dart';
import 'package:fis_jsonrpc/services/index.dart' show ApplyStateEnum;
import 'package:flutter/material.dart';
import 'package:flyinsono/architecture/states/states.dart';
import 'package:flyinsono/pages/user/role_authentication/types.dart';
import 'package:get/get.dart';

const String GeneralUserRoleCode = 'Role_GeneralUser';

class UserCenterState {
  final Rx<String> _userName = Rx('');
  final Rx<String> _fullName = Rx('');
  final Rx<String> _nickName = Rx('');
  final Rx<String> _displayName = Rx('');
  final Rx<String> _avatar = Rx(Store.user.avatar);
  final Rx<Color> _vipColor = Colors.white.obs;
  final Rx<String> _roleCode = Rx('');
  final Rx<String> _roleName = Rx('');
  final Rx<String> _oldPassword = Rx('');
  final Rx<String> _newPassword = Rx('');
  final Rx<String> _newPasswordAgain = Rx('');
  final Rx<String> _verifyCode = Rx('');
  final Rx<bool> _disableSubmit = Rx(true);
  final Rx<int> _seconds = Rx(0);
  final Rx<bool> _isFetching = Rx(false);
  final Rx<ApplyStateEnum> _applyState = Rx(ApplyStateEnum.NotApply);
  final Rx<List<UserRole>> _roles = Rx(<UserRole>[]);
  final Rx<List<String>> _labels = Rx(<String>[]);

  ///是否需要展示第三方页面
  bool get hasAssociatedFeature =>
      Store.user.associatedFeatures.isNotEmpty &&
      Store.user.associatedFeatures
          .any((element) => element.associatedPosition == "PersonCenter");

  ///角色标签（擅长领域）
  List<String> get labels => _labels.value;
  set labels(List<String> value) => _labels(value);

  /// 身份角色集合
  List<UserRole> get roles => _roles.value;
  set roles(List<UserRole> value) => _roles(value);

  /// 是否正在获取验证码
  bool get isFetching => _isFetching.value;
  set isFetching(bool val) => _isFetching(val);

  /// 倒计时读秒
  int get seconds => _seconds.value;
  set seconds(int val) => _seconds(val);

  ///提交
  set disableSubmit(bool v) => _disableSubmit.value = v;
  bool get disableSubmit => _disableSubmit.value;

  ///验证码
  set verifyCode(String v) => _verifyCode.value = v;
  String get verifyCode => _verifyCode.value;

  ///原密码
  set oldPassword(String v) => _oldPassword.value = v;
  String get oldPassword => _oldPassword.value;

  ///新密码
  set newPassword(String v) => _newPassword.value = v;
  String get newPassword => _newPassword.value;

  ///再次输入新密码
  set newPasswordAgain(String v) => _newPasswordAgain.value = v;
  String get newPasswordAgain => _newPasswordAgain.value;

  /// 身份认证角色 code
  set roleCode(String value) => _roleCode.value = value;
  String get roleCode => _roleCode.value;

  /// 身份认证角色 code
  set roleName(String value) => _roleName.value = value;
  String get roleName => _roleName.value;

  // 头像
  set avatar(String value) => _avatar.value = value;
  String get avatar => _avatar.value;

  ///申请状态
  set applyState(ApplyStateEnum value) => _applyState(value);
  ApplyStateEnum get applyState => _applyState.value;

  ///是否已申请
  bool get idRoleApplied =>
      applyState != ApplyStateEnum.NotApply && !isGeneralUserRole;

  ///是否是普通用户
  bool get isGeneralUserRole {
    return roleCode == GeneralUserRoleCode;
  }

  ///是否已认证
  bool get idRolePassed =>
      applyState == ApplyStateEnum.Passed && !isGeneralUserRole;

  /// 认证状态描述
  String get idRoleStateDescription => (idRoleApplied || isGeneralUserRole)
      ? roleName
      : i18nBook.user.notAuthenticated.t;

  ///用户名
  String get userName => _userName.value;
  set userName(String val) => _userName.value = val;

  /// 真实姓名
  String get fullName => _fullName.value;
  set fullName(String val) => _fullName.value = val;

  /// 昵称
  String get nickName => _nickName.value;
  set nickName(String val) => _nickName.value = val;

  /// 外显名称
  String get displayName => _displayName.value;
  set displayName(String val) => _displayName.value = val;

  /// VIP展示颜色
  Color get vipColor => _vipColor.value;
  set vipColor(Color val) => _vipColor.value = val;
}
