import 'package:hmg_patient_app/config/config.dart';
import 'package:hmg_patient_app/config/shared_pref_kay.dart';
import 'package:hmg_patient_app/core/model/contactus/get_hmg_locations.dart';

import '../base_service.dart';

class FindusService extends BaseService {


  List<GetHMGLocationsModel> FindusModelList =[];
  List<GetHMGLocationsModel> FindusHospitalModelList =[];
  List<GetHMGLocationsModel> FindusPharmaciesModelList =[];
  Map<String, dynamic> body = Map();

  Future getAllFindUsOrders() async {
    hasError = false;

    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_FINDUS_REQUEST,
        onSuccess: (dynamic response, int statusCode) {
      FindusModelList.clear();
      FindusHospitalModelList.clear();
      FindusPharmaciesModelList.clear();

      response['ListHMGLocation'].forEach((vital) {
        if (GetHMGLocationsModel.fromJson(vital).locationType == 1) {
          FindusHospitalModelList.add(GetHMGLocationsModel.fromJson(vital));
        } else {
          FindusPharmaciesModelList.add(GetHMGLocationsModel.fromJson(vital));
        }

      });
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: body);
  }
}
