import 'package:flutter_riverpod/flutter_riverpod.dart';

import '../core/network/dio_client.dart';
import '../data/models/asset/account_auth.dart';
import '../data/services/withdraw_service.dart';

/// 安全设置认证状态 Provider
/// 页面进入时加载，从绑定页返回时自动刷新
final securityAuthProvider =
    AutoDisposeAsyncNotifierProvider<SecurityAuthNotifier, AccountAuth>(
  SecurityAuthNotifier.new,
);

class SecurityAuthNotifier extends AutoDisposeAsyncNotifier<AccountAuth> {
  @override
  Future<AccountAuth> build() => _fetch();

  Future<AccountAuth> _fetch() {
    final service = WithdrawService(ref.read(dioClientProvider));
    return service.getSecuritySetting();
  }

  /// 手动刷新（从绑定页返回后调用）
  Future<void> refresh() async {
    state = const AsyncLoading();
    state = await AsyncValue.guard(_fetch);
  }
}
