import 'dart:math';

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

class GameInfoModel extends ChangeNotifier with InjectApi {
  /// 登录
  Future<GameInfoData> getGameInfo() async {
    dynamic data = await api.getGameAll();
    notifyListeners();
    return data;
  }
}

class CommentListModel extends ViewStateRefreshListModel with InjectApi {
  String id;
  String by = "like_count";

  CommentListModel(this.id, {this.by = "like_count"});

  @override
  Future<List> loadData({int pageNum = 1}) async {
    return handlePage(await api.getPostComments(id, page: max(1, pageNum), sortBy: by));
  }

  sortBy(String name) {
    if (name == "点赞最多") {
      by = "like_count";
    } else if (name == "最新评论") {
      by = "created_at";
    }
    initData();
  }
}
