import 'dart:math';

import 'package:sport/bean/user_friend.dart';
import 'package:sport/provider/lib/view_state_refresh_list_model.dart';
import 'package:sport/services/api/inject_api.dart';

class UserFriendModel extends ViewStateRefreshListModel<UserFriend> with InjectApi {
  int type;
  String kw;

  UserFriendModel(this.type);

  @override
  Future<List<UserFriend>> loadData({int pageNum}) async {
    List<UserFriend> results = [];
    switch (type) {
      case 2:
        results = (await api.userFansList(kw: kw, page: max(1, pageNum))).results;
        break;
      case 1:
        results = (await api.userFollowList(kw: kw, page: max(1, pageNum))).results;
        break;
      default:
        results = (await api.userFriends(kw: kw, page: max(1, pageNum))).results;
        break;
    }
    return results;
  }

  void submitValue(String value) {
    this.kw = value;
    refresh(init: true);
  }
}
