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/models/Appointments/AppoimentAllHistoryResultList.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;

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

  Future<bool> sendCOCItem({String title, String details, String cOCTypeName, String attachment, AppoitmentAllHistoryResultList 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);
      return false;
    } else {
      setState(ViewState.Idle);
      return true;
    }
  }

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

  searchFeedback(String countryCode, String phoneNumber, int type, String idNumber) async {
    setState(ViewState.Busy);
    await _feedbackService.searchFeedback(countryCode, phoneNumber, type, idNumber);
    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);
    }
  }
}
