import 'package:diplomaticquarterapp/config/config.dart';
import 'package:diplomaticquarterapp/config/shared_pref_kay.dart';
import 'package:diplomaticquarterapp/core/model/weahter/weather_model.dart';
import 'package:diplomaticquarterapp/core/service/base_service.dart';

class WeatherService extends BaseService {
  List<GetCityInfoList> weatherIndicatorData = List();

  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));
      });
      print(weatherIndicatorData);
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: body);
    await this.sharedPref.setObject(WEATHER, weatherIndicatorData[0]);
    return Future.value(weatherIndicatorData[0]);
  }
}
