import 'package:hmg_patient_app/config/config.dart';
import 'package:hmg_patient_app/core/model/reports/Reports.dart';
import 'package:hmg_patient_app/core/model/reports/request_reports.dart';
import 'package:hmg_patient_app/core/service/base_service.dart';
import 'package:hmg_patient_app/pages/feedback/appointment_history.dart';

class ReportsMonthlyService extends BaseService {
  List<Reports> reportsList =[];
  List<AppointmentHistory> appointHistoryList =[];

  RequestReports _requestReports = RequestReports(
      isReport: true,
      encounterType: 1,
      requestType: 1,
      isDentalAllowedBackend: false,
     );

  Future getReports() async {
    hasError = false;
    await baseAppClient.post(REPORTS,
        onSuccess: (dynamic response, int statusCode) {
      reportsList.clear();
      response['GetPatientMedicalStatus'].forEach((reports) {
        reportsList.add(Reports.fromJson(reports));
      });
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: _requestReports.toJson());
  }

  Future getPatentAppointmentHistory() async {
    hasError = false;
    Map<String, dynamic> body = new Map<String, dynamic>();
    body['IsForMedicalReport'] = true;
   await baseAppClient.post(GET_PATIENT_AppointmentHistory,
        onSuccess: (dynamic response, int statusCode) {
      appointHistoryList = [];
      response['AppoimentAllHistoryResultList'].forEach((appoint) {
        appointHistoryList.add(AppointmentHistory.fromJson(appoint));
      });
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: body);
  }

  Future insertRequestForMedicalReport(
      AppointmentHistory appointmentHistory) async {
    Map<String, dynamic> body = new Map<String, dynamic>();
    body['ClinicID'] = appointmentHistory.clinicID;
    body['DoctorID'] = appointmentHistory.doctorID;
    body['SetupID'] = appointmentHistory.setupID;
    body['EncounterNo'] = appointmentHistory.appointmentNo;
    body['EncounterType'] = 1;// appointmentHistory.appointmentType;
    body['IsActive'] = appointmentHistory.isActiveDoctor;
    body['ProjectID'] = appointmentHistory.projectID;
    body['Remarks'] = "";
    body['ProcedureId'] = "";
    body['RequestType'] = 1;
    body['Source'] = 2;
    body['Status'] = 1;
    body['CreatedBy'] = 102;
    hasError = false;
   await baseAppClient.post(INSERT_REQUEST_FOR_MEDICAL_REPORT,
        onSuccess: (dynamic response, int statusCode) {},
        onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: body);
  }
}
