import 'package:flutter/foundation.dart'; import '../../../core/network/api_client.dart'; import '../../../core/network/api_endpoints.dart'; import '../../models/referral_model.dart'; abstract class ReferralRemoteDataSource { /// 获取当前用户推荐信息 Future getMyReferralInfo(); /// 获取当前用户直推列表 Future getDirectReferrals({ int limit = 50, int offset = 0, }); /// 获取指定用户的直推列表(用于伞下树懒加载) Future getUserDirectReferrals({ required String accountSequence, int limit = 100, int offset = 0, }); } class ReferralRemoteDataSourceImpl implements ReferralRemoteDataSource { final ApiClient client; ReferralRemoteDataSourceImpl({required this.client}); @override Future getMyReferralInfo() async { try { debugPrint('获取推荐信息...'); final response = await client.get(ApiEndpoints.referralMe); if (response.statusCode == 200) { final data = response.data as Map; debugPrint('推荐信息获取成功: directReferralCount=${data['directReferralCount']}'); return ReferralInfoResponse.fromJson(data); } throw Exception('获取推荐信息失败'); } catch (e) { debugPrint('获取推荐信息失败: $e'); rethrow; } } @override Future getDirectReferrals({ int limit = 50, int offset = 0, }) async { try { debugPrint('获取直推列表...'); final response = await client.get( ApiEndpoints.referralDirects, queryParameters: { 'limit': limit, 'offset': offset, }, ); if (response.statusCode == 200) { final data = response.data as Map; debugPrint('直推列表获取成功: total=${data['total']}'); return DirectReferralsResponse.fromJson(data); } throw Exception('获取直推列表失败'); } catch (e) { debugPrint('获取直推列表失败: $e'); rethrow; } } @override Future getUserDirectReferrals({ required String accountSequence, int limit = 100, int offset = 0, }) async { try { debugPrint('获取用户直推列表: accountSequence=$accountSequence'); final response = await client.get( ApiEndpoints.userDirectReferrals(accountSequence), queryParameters: { 'limit': limit, 'offset': offset, }, ); if (response.statusCode == 200) { final data = response.data as Map; debugPrint('用户直推列表获取成功: total=${data['total']}'); return DirectReferralsResponse.fromJson(data); } throw Exception('获取用户直推列表失败'); } catch (e) { debugPrint('获取用户直推列表失败: $e'); rethrow; } } }