import 'package:doctor_app_flutter/config/config.dart';
import 'package:doctor_app_flutter/core/model/doctor/doctor_profile_model.dart';
import 'package:doctor_app_flutter/core/service/base/base_service.dart';
import 'package:doctor_app_flutter/core/model/operation_report/create_update_operation_report_request_model.dart';
import 'package:doctor_app_flutter/core/model/operation_report/get_operation_details_request_modle.dart';
import 'package:doctor_app_flutter/core/model/operation_report/get_operation_details_response_modle.dart';
import 'package:doctor_app_flutter/core/model/operation_report/get_reservations_response_model.dart';
import 'package:doctor_app_flutter/core/model/operation_report/get_reservations_request_model.dart';

import '../../../../config/shared_pref_kay.dart' show DOCTOR_PROFILE;

class OperationReportService extends BaseService {
  List<GetReservationsResponseModel> _reservationList = [];

  List<GetReservationsResponseModel> get reservationList => _reservationList;

  List<GetOperationDetailsResponseModel> _operationDetailsList = [];

  List<GetOperationDetailsResponseModel> get operationDetailsList =>
      _operationDetailsList;

  Future getReservations(
      {GetReservationsRequestModel? getReservationsRequestModel,
      int? patientId,  int? patientMRN}) async {
    Map<String, dynamic>? profile = await sharedPref.getObj(DOCTOR_PROFILE);

    DoctorProfileModel doctorProfile = DoctorProfileModel.fromJson(profile!);
    getReservationsRequestModel =
        GetReservationsRequestModel(patientID: patientId,patientMRN: patientMRN, LoginDoctorID: doctorProfile.doctorID);

    hasError = false;
    await baseAppClient.post(GET_RESERVATIONS,
        onSuccess: (dynamic response, int statusCode) {
      print("Success");
      _reservationList.clear();
      response['List_OTReservationDetails'].forEach(
        (v) {
          _reservationList.add(GetReservationsResponseModel.fromJson(v));
        },
      );
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: getReservationsRequestModel.toJson());
  }

  Future getOperationReportDetails({
    GetOperationDetailsRequestModel? getOperationReportRequestModel,
  }) async {
    hasError = false;
    await baseAppClient.post(GET_OPERATION_DETAILS,
        onSuccess: (dynamic response, int statusCode) {
      print("Success");
      _operationDetailsList.clear();
      response['List_OperationDetails'].forEach(
        (v) {
          _operationDetailsList
              .add(GetOperationDetailsResponseModel.fromJson(v));
        },
      );
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: getOperationReportRequestModel!.toJson());
  }

  Future updateOperationReport(
      CreateUpdateOperationReportRequestModel
          createUpdateOperationReport) async {
    await baseAppClient.post(UPDATE_OPERATION_REPORT,
        onSuccess: (dynamic response, int statusCode) {},
        onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: createUpdateOperationReport.toJson(), isFallLanguage: true);
  }
}
