import 'package:doctor_app_flutter/config/config.dart';
import 'package:doctor_app_flutter/core/model/dashboard/radiology_critical_finding_model.dart';
import 'package:doctor_app_flutter/core/service/base/base_service.dart';
import 'package:doctor_app_flutter/core/model/dashboard/dashboard_model.dart';

import '../../model/dashboard/doctor_schedule.dart';

class DashboardService extends BaseService {
  List<DashboardModel> _dashboardItemsList = [];

  RadiologyCriticalFindingModel? _radiologyCriticalFindingModel;

  List<DashboardModel> get dashboardItemsList => _dashboardItemsList;

  RadiologyCriticalFindingModel? get radiologyCriticalFindingModel => _radiologyCriticalFindingModel;

  bool hasVirtualClinic = false;
  String? sServiceID;

  Future getDashboard() async {
    hasError = false;
    await baseAppClient.post(
      GET_DASHBOARD,
      onSuccess: (dynamic response, int statusCode) {
        _dashboardItemsList.clear();
        response['listDoctorDashboarKPI'].forEach((v) {
          _dashboardItemsList.add(DashboardModel.fromJson(v));
        });
      },
      onFailure: (String error, int statusCode) {
        hasError = true;
        super.error = error;
      },
      body: {},
    );
  }

  Future checkDoctorHasLiveCare() async {
    hasError = false;
    await getDoctorProfile(isGetProfile: true);
    await baseAppClient.post(
      DOCTOR_CHECK_HAS_LIVE_CARE,
      onSuccess: (dynamic response, int statusCode) {
        hasVirtualClinic = response['HasVirtualClinic'];
        sServiceID = response['SserviceID'];
      },
      onFailure: (String error, int statusCode) {
        hasError = true;
        super.error = error;
      },
      body: {
        "DoctorID": doctorProfile?.doctorID // test user 9920
      },
    );
  }

  Future acknowledgeDoctorHasRadiologyFindings(String invoiceNo, String invoiceLineItemNo) async {
    hasError = false;
    await getDoctorProfile(isGetProfile: true);
    await baseAppClient.post(
      ACKNOWLEDGE_RADIOLOGY_CRITICAL_FINDINGS,
      onSuccess: (dynamic response, int statusCode) {
        // _radiologyCriticalFindingModel = RadiologyCriticalFindingModel.fromJson(response["RadiologyVMEntityListInfoResponse"]["entityList"][0]);
      },
      onFailure: (String error, int statusCode) {
        hasError = true;
        super.error = error;
      },
      body: {
        "DoctorID": doctorProfile?.doctorID, // test user 9920
        "LoginDoctorID": doctorProfile?.doctorID,
        "invoiceNo": invoiceNo,
        "invoiceLineItemNo": invoiceLineItemNo,
      },
    );
  }

  Future checkDoctorHasRadiologyFindings() async {
    hasError = false;
    await getDoctorProfile(isGetProfile: true);
    await baseAppClient.post(
      DOCTOR_RADIOLOGY_CRITICAL_FINDINGS,
      onSuccess: (dynamic response, int statusCode) {
        if(response["RadiologyVMEntityListInfoResponse"]["entityList"].length != 0) {
          _radiologyCriticalFindingModel = RadiologyCriticalFindingModel.fromJson(response["RadiologyVMEntityListInfoResponse"]["entityList"][0]);
        }
      },
      onFailure: (String error, int statusCode) {
        hasError = true;
        super.error = error;
      },
      body: {
        "DoctorID": doctorProfile?.doctorID, // test user 9920
        "LoginDoctorID": doctorProfile?.doctorID
      },
    );
  }
}
