import 'package:app_business/service/abase.dart';
import 'package:app_business/service/api.dart';
import 'package:track_common/view/home/data_detail/data_detail_controller.dart';

export 'package:track_common/view/home/data_detail/data_detail.dart';
export 'package:track_common/view/home/data_detail/data_detail_controller.dart';

class DataDetailControllerImpl extends DataDetailController {
  ApiService get api => Get.find();

  @override
  Future<List<int>> getHistoryDetail(int gameId) async {
    final r =
        await api.stub.toHistoryGameDetail(IdRequest()..id = Int64(gameId));
    return r.writeToBuffer();
  }

  @override
  Future<List<UserDetail>> getUserList(int mapId) async {
    final r =
        await api.stub.toHistoryUserListQuery(IdRequest()..id = Int64(mapId));

    return r.list
        .map((e) => UserDetail()
          ..id = e.oId
          ..name = e.oName
          ..history = e.list
              .map((e2) => UserHistorySimple()
                ..gameId = e2.gameId
                ..routeName = e2.courseName
                ..eventName = e2.actName
                ..duration = e2.duration.toModel()
                ..startAt = e2.startAt.toModel())
              .toList())
        .toList();
  }
}
