import 'package:diplomaticquarterapp/core/enum/viewstate.dart';
import 'package:diplomaticquarterapp/core/model/feedback/COC_items.dart';
import 'package:diplomaticquarterapp/core/service/feedback/feedback_service.dart';
import 'package:diplomaticquarterapp/core/viewModels/base_view_model.dart';
import 'package:diplomaticquarterapp/pages/feedback/appointment_history.dart';

import '../../../locator.dart';

enum MessageType {
  ComplaintOnAnAppointment,
  ComplaintWithoutAppointment,
  Question,
  Compliment,
  Suggestion,
  NON
}

class FeedbackViewModel extends BaseViewModel {
  FeedbackService _feedbackService = locator<FeedbackService>();

  List<COCItem> get cOCItemList => _feedbackService.cOCItemList;
  MessageType messageType = MessageType.NON;
  MessageType messageTypeDialog = MessageType.NON;

  String selected = "not selected";

  setMessageDialogType(MessageType messageType) {
    messageTypeDialog = messageType;
    notifyListeners();
  }

    setMessageType(MessageType messageType) {
    this.messageType = messageType;
    switch (messageType) {
      case MessageType.ComplaintOnAnAppointment:
        selected = "Complaint on an appointment";
        break;
      case MessageType.ComplaintWithoutAppointment:
        selected = "Complaint without appointment";
        break;
      case MessageType.Question:
        selected = "Question";
        break;
      case MessageType.Compliment:
        selected = "Compliment";
        break;
      case MessageType.Suggestion:
        selected = "Suggestion";
        break;
      case MessageType.NON:
        break;
    }
    notifyListeners();
  }

  List<AppointmentHistory> get appointHistoryList =>
      _feedbackService.appointHistoryList;

  Future<bool> sendCOCItem(
      {String title,
      String details,
      String cOCTypeName,
      String attachment,
      AppointmentHistory appointHistory}) async {
    setState(ViewState.BusyLocal);
    await _feedbackService.sendCOCItem(
        title: title,
        details: details,
        cOCTypeName: cOCTypeName,
        attachment: attachment,
        appointHistory: appointHistory);
    if (_feedbackService.hasError) {
      error = _feedbackService.error;
      setState(ViewState.ErrorLocal);
      setMessageType(MessageType.NON);
      return false;
    } else {
      setState(ViewState.Idle);
      setMessageType(MessageType.NON);
      return true;
    }
  }

  getCOC() async {
    setState(ViewState.Busy);
    await _feedbackService.getStatusCOC();
    if (_feedbackService.hasError) {
      error = _feedbackService.error;
      setState(ViewState.Error);
    } else {
      setState(ViewState.Idle);
    }
  }

 Future getPatentAppointmentHistory() async {
    setState(ViewState.Busy);
    await _feedbackService.getPatentAppointmentHistory();
    if (_feedbackService.hasError) {
      error = _feedbackService.error;
      setState(ViewState.Error);
    } else {
      setState(ViewState.Idle);
    }
  }
}
