import 'package:hmg_patient_app/config/config.dart';
import 'package:hmg_patient_app/core/model/sick_leave/sick_leave.dart';
import 'package:hmg_patient_app/core/service/base_service.dart';

class PatientSickLeaveService extends BaseService {
  List<SickLeave> sickLeaveList = [];

  String sickLeavePDF = "";

  getSickLeave() async {
    hasError = false;
    super.error = "";
    await baseAppClient.post(GET_PATIENT_SICK_LEAVE_STATUS, onSuccess: (response, statusCode) async {
      sickLeaveList.clear();
      if (response['List_SickLeave'] != null && response['List_SickLeave'].length != 0) {
        response['List_SickLeave'].forEach((sickLeave) {
          sickLeaveList.add(SickLeave.fromJson(sickLeave));
        });
      }
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: Map());
  }

  sendSickLeaveEmail({required int requestNo, required String projectName, required String doctorName, required int projectID, required String setupID, required bool isDownload}) async {
    hasError = false;
    super.error = "";
    Map<String, dynamic> body = Map();
    body['RequestNo'] = requestNo;
    body['To'] = user.emailAddress;
    body['DateofBirth'] = user.dateofBirth;
    body['PatientIditificationNum'] = user.patientIdentificationNo;
    body['PatientMobileNumber'] = user.mobileNumber;
    body['PatientName'] = user.firstName! + " " + user.firstName!;
    body['ProjectName'] = projectName;
    body['DoctorName'] = doctorName;
    body['ProjectID'] = projectID;
    body['SetupID'] = setupID;
    body['IsDownload'] = isDownload;
    await baseAppClient.post(SendSickLeaveEmail, onSuccess: (response, statusCode) async {
      if(isDownload) {
        sickLeavePDF = response['Base64Data'];
      }
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: body);
  }
}
