import 'package:flutter/material.dart';
import 'package:qadirneyriz/global/global_class/selected_item.dart';
import 'package:qadirneyriz/services/meetings/meetings.dart';
import 'package:qadirneyriz/utils/enums/status.dart';

class MeetinAddState extends ChangeNotifier {
  MeetingsApi meetingApi = MeetingsApi();
  // date
  String? fromDate;
  void setFromDate(String date) {
    fromDate = date;
    notifyListeners();
  }

// subject
  ItemSelected selectedSubject = ItemSelected();
// location
  ItemSelected selectedLocation = ItemSelected();
  // manager
  ItemSelected selectedManager = ItemSelected();
  //users
  List<int> selectedUsersItems = [];
  // time
  TimeOfDay selectedStartTime =
      TimeOfDay(hour: TimeOfDay.now().hour, minute: TimeOfDay.now().minute);
  TimeOfDay selectedEndTime =
      TimeOfDay(hour: TimeOfDay.now().hour, minute: TimeOfDay.now().minute);

  // add meeting

  Status statusAddMeeting = Status.empty;
  String? messageAddMeeting;
  Map? errorsAddMeeting;

  Future<Status> addMeeting(
      {int? locationId,
      int? subjectId,
      int? managerId,
      required String fromHour,
      required String toHour,
      required String dateMeeting,
      required List<int> members}) async {
    statusAddMeeting = Status.loading;
    notifyListeners();
    try {
      final result = await meetingApi.addMeetingApi(
          locationId: locationId,
          subjectId: subjectId,
          managerId: managerId,
          fromHour: fromHour,
          toHour: toHour,
          dateMeeting: dateMeeting,
          members: members);
      if (result.isOk) {
        statusAddMeeting = Status.ready;
        messageAddMeeting = result.message;
      } else if (result.isOk == false) {
        // print(result.isOk);
        errorsAddMeeting = result.errors;
        messageAddMeeting = result.message;
        statusAddMeeting = Status.error;
      } else {
        statusAddMeeting = Status.error;
      }
      notifyListeners();
    } catch (e) {
      statusAddMeeting = Status.error;
      // print(e);
    }
    notifyListeners();
    // print(statusAddMeeting);
    return statusAddMeeting;
  }
}
