import 'package:diplomaticquarterapp/config/config.dart';
import 'package:diplomaticquarterapp/core/model/doctor/doctor_profile.dart';
import 'package:diplomaticquarterapp/core/model/doctor/doctor_rating.dart';
import 'package:diplomaticquarterapp/core/model/doctor/patient_doctor_appointment.dart';
import 'package:diplomaticquarterapp/core/model/doctor/reques_patient_doctor_appointmentt.dart';
import 'package:diplomaticquarterapp/core/model/doctor/request_doctor_profile.dart';
import 'package:diplomaticquarterapp/core/model/doctor/request_doctor_rating.dart';
import 'package:diplomaticquarterapp/core/service/base_service.dart';

class MyDoctorService extends BaseService {
  List<PatientDoctorAppointment> patientDoctorAppointmentList = List();
  DoctorProfile doctorProfile;
  DoctorRating doctorRating = DoctorRating();

  RequestPatientDoctorAppointment patientDoctorAppointmentRequest =
      RequestPatientDoctorAppointment(
          top: 0,
          versionID: 5.5,
          beforeDays: 0,
          exludType: 4,
          channel: 3,
          languageID: 2,
          iPAdress: '10.20.10.20',
          generalid: 'Cs2020@2016\$2958',
          patientOutSA: 0,
          sessionID: 'TMRhVmkGhOsvamErw',
          isDentalAllowedBackend: false,
          deviceTypeID: 1,
          patientID: 1231755,
          tokenID: '@dm!n',
          patientType: 1,
          patientTypeID: 1);

  RequestDoctorRating _requestDoctorRating = RequestDoctorRating(
      channel: 3,
      deviceTypeID: 2,
      doctorID: 2477,
      iPAdress: '10.20.10.20',
      languageID: 2,
      patientOutSA: 0,
      sessionID: 'CvsUFeJkyLDnFQqw',
      versionID: 5.5,
      generalid: 'Cs2020@2016\$2958',
      isDentalAllowedBackend: false);

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

  RequestDoctorProfile _requestDoctorProfile = RequestDoctorProfile(
    doctorID: 2477,
    license: true,
    isRegistered: true,
    projectID: 12,
    clinicID: 501,
    patientID: 1231755,
    versionID: 5.5,
    channel: 3,
    languageID: 2,
    iPAdress: '10.20.10.20',
    generalid: 'Cs2020@2016\$2958',
    patientOutSA: 0,
    sessionID: 'nstatCtNEmuwxeuVAOUmw',
    isDentalAllowedBackend: false,
    deviceTypeID: 2,
  );

  Future getDoctorProfileAndRating({int doctorId,int clinicID,int projectID }) async {
    ///GET DOCTOR PROFILE
    _requestDoctorProfile.doctorID = doctorId;
    _requestDoctorProfile.clinicID = clinicID;
    _requestDoctorProfile.patientID = projectID;
    hasError = false;
    await baseAppClient.post(GET_DOCTOR_PROFILE,
        onSuccess: (dynamic response, int statusCode) {
      doctorProfile = DoctorProfile.fromJson(response['DoctorProfileList'][0]);
    }, 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());
  }
}
