import 'package:diplomaticquarterapp/config/config.dart';
import 'package:diplomaticquarterapp/core/model/ask_doctor/AskDoctorReqTypes.dart';
import 'package:diplomaticquarterapp/core/model/ask_doctor/DoctorResponse.dart';
import 'package:diplomaticquarterapp/core/service/base_service.dart';
import 'package:diplomaticquarterapp/models/Appointments/DoctorListResponse.dart';
import 'package:diplomaticquarterapp/uitl/date_uitl.dart';

class AskDoctorService extends BaseService {
  List<AskDoctorReqTypes> askDoctorReqTypes = List();
  List<DoctorResponse> doctorResponseList = List();

  Future getCallInfoHoursResult({int projectId, int doctorId}) async {
    hasError = false;
    Map<String, dynamic> body = Map();
    body['isDentalAllowedBackend'] = false;
    body['DoctorID'] = doctorId;
    body['ProjectID'] = projectId;

    dynamic localRes;

    await baseAppClient.post(GET_CALL_INFO_HOURS_RESULT,
        onSuccess: (dynamic response, int statusCode) {
          localRes = response;
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: body);
    return Future.value(localRes);
  }

  Future getCallRequestTypeLOV() async {
    hasError =false;
    Map<String, dynamic> body = Map();
    body['isDentalAllowedBackend'] = false;
    await baseAppClient.post(GET_CALL_REQUEST_TYPE_LOV,
        onSuccess: (dynamic response, int statusCode) {
      askDoctorReqTypes.clear();
      response['ListReqTypes'].forEach((reqType) {
        askDoctorReqTypes.add(AskDoctorReqTypes.fromJson(reqType));
      });
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: body);
  }

  Future getDoctorResponse() async {
    hasError =false;
    Map<String, dynamic> body = Map();
    body['isDentalAllowedBackend'] = false;
    body['from'] =
        "${DateTime.now().year}-${DateTime.now().month}-${DateTime.now().day} 00:00:00";
    body['from'] =
        "${DateTime.now().year}-${DateTime.now().month}-${DateTime.now().day} ${DateTime.now().hour}:${DateTime.now().minute}:00";
    await baseAppClient.post(GET_DOCTOR_RESPONSE,
        onSuccess: (dynamic response, int statusCode) {
      doctorResponseList.clear();
      response['List_DoctorResponse'].forEach((reqType) {
        doctorResponseList.add(DoctorResponse.fromJson(reqType));
      });
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: body);
  }

  Future updateReadStatus({int transactionNo}) async {
    hasError =false;
    Map<String, dynamic> body = Map();
    body['isDentalAllowedBackend'] = false;
    body['TransactionNo'] = transactionNo;
    await baseAppClient.post(UPDATE_READ_STATUS,
        onSuccess: (dynamic response, int statusCode) {
      //TODO fix it
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: body);
  }


  Future sendRequestLOV({DoctorList doctorList,String requestType,String remark}) async {
    hasError =false;
    Map<String, dynamic> body = Map();
    body['ProjectID'] = doctorList.projectID;
    body['SetupID'] = doctorList.setupID;
    body['DoctorID'] = doctorList.doctorID;
    body['PatientMobileNumber'] = user.mobileNumber;
    body['IsMessageSent'] = false;
    body['RequestDate'] = DateUtil.yearMonthDay(DateTime.now());
    body['RequestTime'] = DateUtil.time(DateTime.now());
    body['Remarks'] = remark;
    body['Status'] = 2;// 4 for testing only.."cancelled status insert" else should be changed to 1 in live version
    body['CreatedBy'] = 102;
    body['CreatedOn'] =  DateUtil.yearMonthDay(DateTime.now());
    body['EditedBy'] = 102;
    body['EditedOn'] = DateUtil.yearMonthDay(DateTime.now());
    body['isDentalAllowedBackend'] = false;
    await baseAppClient.post(INSERT_CALL_INFO,
        onSuccess: (dynamic response, int statusCode) {

        }, onFailure: (String error, int statusCode) {
          hasError = true;
          super.error = error;
        }, body: body);
  }

}
