import 'dart:async';

import 'package:flutter/cupertino.dart';
import 'package:initial_folder/models/announcement_model.dart';
import 'package:initial_folder/services/announcement_service.dart';
import 'package:rxdart/rxdart.dart';

enum DataState { loading, noData, hasData, error }

enum ResultStateLike { loading, error }

class ReplyAnnouncementProvider with ChangeNotifier {
  final _service = AnnouncementService();

  StreamController<AnnouncementModel> streamController = BehaviorSubject();

  String _message = '';
  String get message => _message;

  DataState? _state;
  DataState? get state => _state;

  AnnouncementModel? _announcementModel;
  AnnouncementModel? get result => _announcementModel;

  set announcementModel(AnnouncementModel? announcementModel) {
    _announcementModel = announcementModel;
    notifyListeners();
  }

  Stream<AnnouncementModel> get replyAnnouncementStream {
    return streamController.stream;
  }

  Future<void> getReplyAnnouncement(String idCourse, int index) async {
    AnnouncementModel announcementModel =
        await _service.getAnnouncement(idCourse);
    streamController.add(announcementModel);
  }
}
