import 'package:flutter/material.dart';
import 'package:initial_folder/services/announcement_service.dart';

enum ResultState { uninitilized, loading, failed, success }

class LikeOrAnnouncementProvider with ChangeNotifier {
  ResultState _state = ResultState.uninitilized;

  ResultState get state => _state;

  Future<bool> likeOrAnnouncement(String tokenAnnouncement) async {
    try {
      _state = ResultState.loading;
      notifyListeners();

      bool response =
          await AnnouncementService().likeAnnouncement(tokenAnnouncement);
      if (response) {
        _state = ResultState.success;
        notifyListeners();
        return true;
      } else {
        _state = ResultState.failed;
        notifyListeners();
        return false;
      }
    } catch (e) {
      _state = ResultState.failed;
      notifyListeners();
      return false;
    }
  }
}
