import 'package:doctor_app_flutter/config/config.dart';
import 'package:doctor_app_flutter/core/service/base/base_service.dart';
import 'package:doctor_app_flutter/models/sickleave/add_sickleave_request.dart';
import 'package:doctor_app_flutter/models/sickleave/extend_sick_leave_request.dart';
import 'package:doctor_app_flutter/models/sickleave/get_all_sickleave_response.dart';
// import 'package:doctor_app_flutter/models/dashboard/dashboard_model.dart';

class SickLeaveService extends BaseService {
  Map get sickLeavestatisitics => _statistics;
  Map _statistics = {};

  List<GetAllSickLeaveResponse> get getAllSickLeave => _getAllsickLeave;
  List<GetAllSickLeaveResponse> _getAllsickLeave = [];
  Future getStatistics(appoNo, patientMRN) async {
    hasError = false;
    await baseAppClient.post(
      GET_SICKLEAVE_STATISTIC,
      onSuccess: (dynamic response, int statusCode) {
        print(response);
        _statistics = {};
        _statistics = response['SickLeaveStatistics'];
      },
      onFailure: (String error, int statusCode) {
        hasError = true;
        super.error = error;
      },
      body: {"PatientMRN": patientMRN, "AppointmentNo": appoNo},
    );
  }

  Future addSickLeave(AddSickLeaveRequest addSickLeaveRequest) async {
    addSickLeaveRequest.appointmentNo = '2016054661';
    addSickLeaveRequest.patientMRN = '3120746';
    hasError = false;
    await baseAppClient.post(
      ADD_SICK_LEAVE,
      onSuccess: (dynamic response, int statusCode) {
        Future.value(response);
        print(response);
        // _statistics = {};
        // _statistics = response['SickLeaveStatistics'];
      },
      onFailure: (String error, int statusCode) {
        hasError = true;
        super.error = error;
      },
      body: addSickLeaveRequest.toJson(),
    );
  }

  Future extendSickLeave(GetAllSickLeaveResponse request) async {
    var extendSickLeaveRequest = ExtendSickLeaveRequest();
    extendSickLeaveRequest.patientMRN =
        request.patientMRN.toString(); //'3120746';
    extendSickLeaveRequest.previousRequestNo = request.requestNo.toString();
    extendSickLeaveRequest.noOfDays = request.noOfDays.toString();
    extendSickLeaveRequest.remarks = request.remarks;
    hasError = false;
    await baseAppClient.post(
      EXTEND_SICK_LEAVE,
      onSuccess: (dynamic response, int statusCode) {
        Future.value(response);
        print(response);
        // _statistics = {};
        // _statistics = response['SickLeaveStatistics'];
      },
      onFailure: (String error, int statusCode) {
        hasError = true;
        super.error = error;
      },
      body: extendSickLeaveRequest.toJson(),
    );
  }

  Future getSickLeave() async {
    hasError = false;
    await baseAppClient.post(
      GET_SICK_LEAVE,
      onSuccess: (dynamic response, int statusCode) {
        Future.value(response);
        _getAllsickLeave.clear();
        response['SickLeavesList']['entityList'].forEach((v) {
          _getAllsickLeave.add(GetAllSickLeaveResponse.fromJson(v));
        });
      },
      onFailure: (String error, int statusCode) {
        hasError = true;
        super.error = error;
      },
      body: {'PatientMRN': 3120772},
    );
  }
}
