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/weahter/weather_model.dart';
import 'package:hmg_patient_app/core/service/base_service.dart';

class WeatherService extends BaseService {
  List<GetCityInfoList> weatherIndicatorData =[];

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

  Future getWeatherData() 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;
    weatherIndicatorData = [];
    await baseAppClient.post(WEATHER_INDICATOR,
        onSuccess: (dynamic response, int statusCode) {
      response['GetCityInfo_List'].forEach((data) {
        weatherIndicatorData.add(GetCityInfoList.fromJson(data));
      });
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: body);
    await this.sharedPref.setObject(WEATHER, weatherIndicatorData[0]);
    return Future.value(weatherIndicatorData[0]);
  }
}
