import 'package:diplomaticquarterapp/config/config.dart';
import 'package:diplomaticquarterapp/config/shared_pref_kay.dart';
import 'package:diplomaticquarterapp/core/model/er/projectavgerwaitingtime.dart';
import '../base_service.dart';

class ErService extends BaseService {
  List<ProjectAvgERWaitingTime> projectAvgERWaitingTimeModelList = List();

  Map<String, dynamic> body = Map();
  String Latitude = "";
  String Longitude = "";
  String PhoneNumber = "";

  Future getProjectAvgERWaitingTimeOrders({int id, int projectID}) async {
    hasError = false;

    if (id != null && projectID != null) {
      body['ID'] = id;
      body['ProjectID'] = projectID;
    }
    var lat = await sharedPref.getDouble(USER_LAT);
    var long = await sharedPref.getDouble(USER_LONG);
    body['Latitude'] = lat ?? 0;
    body['Longitude'] = long ?? 0;

    await baseAppClient.post(GET_NEAREST_HOSPITAL,
        onSuccess: (dynamic response, int statusCode) {
      projectAvgERWaitingTimeModelList.clear();
      response['List_ProjectAvgERWaitingTime'].forEach((vital) {
        projectAvgERWaitingTimeModelList
            .add(ProjectAvgERWaitingTime.fromJson(vital));
      });
      projectAvgERWaitingTimeModelList.forEach((element) {
        Latitude = '${element.latitude}';
        Longitude = '${element.longitude}';
        PhoneNumber = '${element.phoneNumber}';
      });
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: body);
  }
}
