
import 'package:flutter_app_badger/flutter_app_badger.dart';

import '../../api/apiResponse.dart';
import '../../api/marianumcloud/talk/room/getRoomCache.dart';
import '../../api/marianumcloud/talk/room/getRoomResponse.dart';
import '../dataHolder.dart';

class ChatListProps extends DataHolder {
  GetRoomResponse? _getRoomResponse;
  GetRoomResponse get getRoomsResponse => _getRoomResponse!;

  @override
  List<ApiResponse?> properties() {
    return [_getRoomResponse];
  }

  @override
  void run({renew}) {
    GetRoomCache(
      renew: renew,
      onUpdate: (GetRoomResponse data) => {
        _getRoomResponse = data,
        notifyListeners(),
        FlutterAppBadger.updateBadgeCount(data.data.map((e) => e.unreadMessages).reduce((a, b) => a+b))
      }
    );
  }

}