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

class PrivateMeetingAddState extends ChangeNotifier {
  PrivateMeetingsApi privateMeetingApi = PrivateMeetingsApi();
  // 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> addPrivateMeeting({
    int? locationId,
    int? subjectId,
    int? managerId,
    required String fromHour,
    required String toHour,
    required String dateMeeting,
    required String visitorName,
    required String visitorMobile,
    required String visitorRole,
    required String visitorCompany,
  }) async {
    statusAddMeeting = Status.loading;
    notifyListeners();
    try {
      final result = await privateMeetingApi.addPrivateMeetingApi(
          locationId: locationId,
          subjectId: subjectId,
          managerId: managerId,
          fromHour: fromHour,
          toHour: toHour,
          dateMeeting: dateMeeting,
          visitorCompany: visitorCompany,
          visitorMobile: visitorMobile,
          visitorName: visitorName,
          visitorRole: visitorRole);
      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;
  }
}
