import 'package:doctor_app_flutter/config/config.dart';
import 'package:doctor_app_flutter/core/model/patient/patiant_info_model.dart';
import 'package:doctor_app_flutter/core/model/patient_muse/PatientSearchRequestModel.dart';
import 'package:doctor_app_flutter/core/service/base/base_service.dart';
import 'package:flutter/material.dart';

class PatientInPatientService extends BaseService {
  List<PatiantInformtion> inPatientList = [];
  List<PatiantInformtion> myInPatientList = [];

  Future getInPatientList(PatientSearchRequestModel requestModel, bool isMyInpatient,
      {bool isVidaPlusProject = false}) async {
    hasError = false;
    await getDoctorProfile(isGetProfile: true);
    requestModel.loginDoctorID = doctorProfile!.doctorID;
    if (isMyInpatient) {
      requestModel.doctorID = doctorProfile!.doctorID;
    } else {
      requestModel.doctorID = 0;
    }
    if(isVidaPlusProject == false){
      requestModel.identificationNo = "0";
      requestModel.to = "0";
      requestModel.from = "0";
    }
    await baseAppClient.post(
      GET_PATIENT_IN_PATIENT_LIST,
      onSuccess: (dynamic response, int statusCode) {
        inPatientList.clear();
        myInPatientList.clear();
        response['List_MyInPatient'].forEach((v) {
          PatiantInformtion patient = PatiantInformtion.fromJson(v);
          inPatientList.add(patient);
          if (patient.doctorId == doctorProfile!.doctorID) {
            myInPatientList.add(patient);
          }
        });
      },
      onFailure: (String error, int statusCode) {
        hasError = true;
        super.error = error;
      },
      body: requestModel.toJson(),
    );
  }
}
