import 'package:flutter/material.dart';
import 'package:qadirneyriz/models/home/home_models.dart';
import 'package:qadirneyriz/services/home/home.dart';
import 'package:qadirneyriz/utils/enums/status.dart';

class HomeState extends ChangeNotifier {
  HomeApi homeApi = HomeApi();

  Status todayMettingsStatus = Status.empty;
  TodayMeetingModel? todayMeetingsModel;
  getTodayMeetings({bool refresh = false}) async {
    todayMettingsStatus = Status.loading;
    notifyListeners();
    if (refresh) {
      todayMettingsStatus = Status.loading;
      notifyListeners();
    }

    if (todayMeetingsModel != null) {
      todayMettingsStatus = Status.ready;
      try {
        todayMeetingsModel = await homeApi.getTodayMeetings();
        if (todayMeetingsModel != null) {
          todayMettingsStatus = Status.ready;
        } else {
          todayMettingsStatus = Status.empty;
        }
      } catch (e) {
        todayMettingsStatus = Status.error;
        // print(e);
      }
      notifyListeners();
    } else {
      try {
        todayMeetingsModel = await homeApi.getTodayMeetings();
        if (todayMeetingsModel != null) {
          todayMettingsStatus = Status.ready;
        } else {
          todayMettingsStatus = Status.empty;
        }
        notifyListeners();
      } catch (e) {
        todayMettingsStatus = Status.error;
        print(e);
      }
    }
    notifyListeners();
    print(todayMettingsStatus);
    return todayMettingsStatus;
  }

}
