import 'package:diplomaticquarterapp/core/enum/viewstate.dart';
import 'package:diplomaticquarterapp/core/model/notifications/get_notifications_request_model.dart';
import 'package:diplomaticquarterapp/core/model/notifications/get_notifications_response_model.dart';
import 'package:diplomaticquarterapp/core/model/notifications/mark_message_as_read_request_model.dart';
import 'package:diplomaticquarterapp/core/service/notifications_service.dart';
import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart';
import 'package:flutter/material.dart';

import '../../locator.dart';
import 'base_view_model.dart';

class NotificationViewModel extends BaseViewModel {
  NotificationService _notificationService = locator<NotificationService>();

  List<GetNotificationsResponseModel> get notifications =>
      _notificationService.notificationsList;

  Future getNotifications(
      GetNotificationsRequestModel getNotificationsRequestModel, BuildContext context) async {
    if(getNotificationsRequestModel.currentPage == 0)
      setState(ViewState.Busy);

    await _notificationService
        .getAllNotifications(getNotificationsRequestModel);
    if (_notificationService.hasError) {
      error = _notificationService.error;
        setState(ViewState.Error);
    } else {
        setState(ViewState.Idle);
    }
  }

  Future markAsRead(id) async {
    // setState(ViewState.Busy);
    MarkMessageAsReadRequestModel markMessageAsReadRequestModel =
        new MarkMessageAsReadRequestModel(notificationPoolID: id);
    await _notificationService.markAsRead(markMessageAsReadRequestModel);
      setState(ViewState.Idle);
  }
}