import 'dart:convert';
import 'package:http/http.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../../Model/Response/Appconfig/Appconfigresponse.dart';

class AppConfigurationService{

  Future<AppConfigResponse?> getAppConfig(
      String urldata,
      ) async {
    AppConfigResponse? appConfigResponse;
    try {
      final url = Uri.parse(urldata);

      final response = await get(url, headers: {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
        // 'Authorization': '$token',
      });
      print('appConfigResponsesproviderurldata!!!!!!!!${urldata.toString()}');
      Map<String, dynamic> parsedJson  = json.decode(response.body.toString());

      appConfigResponse = AppConfigResponse.fromJson(parsedJson);
      SharedPreferences prefs = await SharedPreferences.getInstance();

      // prefs.setString('clientid', appConfigResponse.details?.clientid??'');
      prefs.setString('fcmkey', appConfigResponse.details?.fcmkey??'');
      prefs.setString('googleApiKey',appConfigResponse.details?.googleapikey??'');

      // print('appConfigResponseclientid${appConfigResponse.details?.clientid}');
      print('appConfigResponsegoogleapikey${appConfigResponse.details?.googleapikey}');
    } catch (e) {
      print(e.toString());
      print("error");
    }
    return appConfigResponse;
  }

}