import 'package:hmg_patient_app/config/config.dart';
import 'package:hmg_patient_app/core/model/doctor/doctor_profile.dart';
import 'package:hmg_patient_app/core/model/doctor/doctor_rating.dart';
import 'package:hmg_patient_app/core/model/doctor/reques_patient_doctor_appointmentt.dart';
import 'package:hmg_patient_app/core/model/doctor/request_doctor_profile.dart';
import 'package:hmg_patient_app/core/model/doctor/request_doctor_rating.dart';
import 'package:hmg_patient_app/core/service/base_service.dart';
import 'package:hmg_patient_app/models/Appointments/DoctorListResponse.dart';

class MyDoctorService extends BaseService {
  List<DoctorList> patientDoctorAppointmentList =[];
  DoctorProfile? doctorProfile;
  DoctorList? doctorList;
  DoctorRating doctorRating = DoctorRating();

  RequestPatientDoctorAppointment patientDoctorAppointmentRequest =
      RequestPatientDoctorAppointment(
    isDentalAllowedBackend: false,
  );

  RequestDoctorRating _requestDoctorRating = RequestDoctorRating(
      channel: 3,
      deviceTypeID: 2,
      doctorID: 2477,
      isDentalAllowedBackend: false);

  Future getPatientDoctorAppointmentList({int top = 0, int beforeDays = 0,int exludType=4}) async {
    hasError = false;
    patientDoctorAppointmentRequest.top = top;
    patientDoctorAppointmentRequest.beforeDays = beforeDays;
    patientDoctorAppointmentRequest.exludType = exludType;

    await baseAppClient.post(GET_MY_DOCTOR,
        onSuccess: (dynamic response, int statusCode) {
      patientDoctorAppointmentList.clear();
      response['PatientDoctorAppointmentResultList'].forEach((hospital) {
        patientDoctorAppointmentList
            .add(DoctorList.fromJson(hospital));
      });
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: patientDoctorAppointmentRequest.toJson());
  }

  RequestDoctorProfile _requestDoctorProfile = RequestDoctorProfile(
    license: true,
    isRegistered: true,
  );

  Future getDoctorProfileAndRating(
      {required int doctorId, required int clinicID, required int projectID}) async {
    ///GET DOCTOR PROFILE
    _requestDoctorProfile.doctorID = doctorId;
    _requestDoctorProfile.clinicID = clinicID;
    _requestDoctorProfile.projectID = projectID;
    hasError = false;
    await baseAppClient.post(GET_DOCTOR_PROFILE,
        onSuccess: (dynamic response, int statusCode) {
      doctorProfile = DoctorProfile.fromJson(response['DoctorProfileList'][0]);
      doctorList = DoctorList.fromJson(response['DoctorProfileList'][0]);
      doctorList!.clinicName = doctorProfile!.clinicDescription!;
      doctorList!.doctorTitle = doctorProfile!.doctorTitleForProfile!;
      doctorList!.name = doctorProfile!.doctorName!;
      doctorList!.projectName = doctorProfile!.projectName!;
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: _requestDoctorProfile.toJson());

    ///GET DOCTOR RATING
    _requestDoctorRating.doctorID = doctorId;
    await baseAppClient.post(GET_DOCTOR_RATING,
        onSuccess: (dynamic response, int statusCode) {
      doctorRating = DoctorRating.fromJson(response['AvgDoctorRatingList'][0]);
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: _requestDoctorRating.toJson());
  }
}
