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

import '../base_service.dart';

class FindusService extends BaseService {


  List<GetHMGLocationsModel> FindusModelList = List();
  List<GetHMGLocationsModel> FindusHospitalModelList = List();
  List<GetHMGLocationsModel> FindusPharmaciesModelList = List();
  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);
  }
}
