// ============================================================
// WalletProvider — 钱包 Riverpod Providers
//
// 钱包 API 直接通过 ApiClient 调用，无单独 Service 类。
// ============================================================

import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../../../core/network/api_client.dart';

final apiClientProvider = Provider<ApiClient>((ref) {
  return ApiClient.instance;
});

// ── 钱包余额 ──────────────────────────────────────────────────

final walletBalanceProvider = FutureProvider.autoDispose((ref) async {
  final api = ref.read(apiClientProvider);
  final resp = await api.get('/api/v1/wallet/balance');
  return resp.data['data'] as Map<String, dynamic>?;
});

// ── 交易记录 ──────────────────────────────────────────────────

class TransactionParams {
  final int page;
  final int pageSize;
  final String? type;
  const TransactionParams({this.page = 1, this.pageSize = 20, this.type});
}

final transactionRecordsProvider =
    FutureProvider.autoDispose.family<dynamic, TransactionParams>((ref, params) async {
  final api = ref.read(apiClientProvider);
  final resp = await api.get('/api/v1/wallet/transactions', queryParameters: {
    'page': params.page,
    'pageSize': params.pageSize,
    if (params.type != null) 'type': params.type,
  });
  return resp.data['data'];
});
