import 'dart:convert';

// import 'package:http/http.dart' as http;
import 'package:test_sa/controllers/api_routes/api_manager.dart';
import 'package:test_sa/controllers/api_routes/urls.dart';
import 'package:test_sa/modules/signup/models/group_model.dart';
import 'package:test_sa/providers/loading_list_notifier.dart';

class AssetGroupProvider extends LoadingListNotifier<AssetGroup> {
  @override
  Future getData({int? id}) async {
    if (loading) return -2;
    loading = true;
    notifyListeners();

    try {
      // Use direct HTTP call without authentication token
      final headers = {
        'Content-Type': 'application/json',
        'X-Timezone-Offset': DateTime.now().timeZoneOffset.toString().split(".").first,
      };

      // final response = await http.get(
      //   Uri.parse(URLs.signUpGetAssetGroups),
      //   headers: headers,
      // );

      var response = await ApiManager.instance.get(URLs.signUpGetAssetGroups);

      stateCode = response.statusCode;

      if (response.statusCode >= 200 && response.statusCode < 300) {
        List categoriesListJson = json.decode(response.body)["data"];
        items = categoriesListJson.map((item) => AssetGroup.fromJson(item)).toList();
      }

      loading = false;
      notifyListeners();
      return response.statusCode;
    } catch (error) {
      loading = false;
      stateCode = -1;
      notifyListeners();
      return -1;
    }
  }
}
