import 'dart:convert';

import 'package:shared_preferences/shared_preferences.dart';
import 'package:traderscircuit/Utils/api_urls.dart';
import 'package:traderscircuit/Utils/base_manager.dart';
import 'package:traderscircuit/data/network/network_api_services.dart';
import 'package:traderscircuit/model/ProfileModel/GetProfileModel.dart';

ProfileModel? ProfileObj;

class GetProfile {
  GetProfile();

  Future<ResponseData<dynamic>> GetProfileAPI() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    final response = await NetworkApiServices().getApi(ApiUrls.Getprofile);

    if (response.status == ResponseStatus.SUCCESS) {
      dynamic responseData = response.data;

      if (responseData is Map<String, dynamic>) {
        // Assuming response data is a map
        ProfileObj = ProfileModel.fromJson(responseData);
      } else if (responseData is String) {
        // Parse the JSON string into a map
        Map<String, dynamic> jsonMap;
        try {
          jsonMap = json.decode(responseData);
        } catch (e) {
          return ResponseData<dynamic>(
              "Error decoding JSON string: $responseData",
              ResponseStatus.FAILED);
        }
      } else {
        // Handle other types if necessary
        return ResponseData<dynamic>(
            "Unexpected response format", ResponseStatus.FAILED);
      }
    }
    return response;
  }
}
