import 'dart:convert';
import 'dart:core';

import 'package:unit2/model/passo/assessment_level.dart';
import 'package:unit2/sevices/offline/offline_passo/admin/sql_services/sql_services.dart';
import 'package:unit2/utils/request.dart';
import 'package:unit2/utils/urls.dart';
import 'package:http/http.dart' as http;

class AssessmentLevelApiServices {
  static final AssessmentLevelApiServices _instance =
      AssessmentLevelApiServices();
  static AssessmentLevelApiServices get instance => _instance;

  String xClientKey = "unitK3CQaXiWlPReDsBzmmwBZPd9Re1z";
  String xClientKeySecret = "unitcYqAN7GGalyz";

  Future<List<Map<String, dynamic>>> fetch() async {
    String path = Url.instance.getAssessmentLevel();
    Map<String, String> headers = {
      'Content-Type': 'application/json; charset=UTF-8',
      'X-Client-Key': xClientKey,
      'X-Client-Secret': xClientKeySecret
    };

    try {
      http.Response response = await Request.instance
          .getRequest(param: {}, path: path, headers: headers);

      print(response.statusCode);
      print(response.body); // Print for debugging

      if (response.statusCode == 200) {
        // Directly parse the JSON as a list of maps
        final List<Map<String, dynamic>> result =
            List<Map<String, dynamic>>.from(jsonDecode(response.body));
        print(result); // Print result for debugging
        return result;
      } else {
        throw Exception(response.reasonPhrase);
      }
    } catch (e) {
      throw Exception(e.toString());
    }
  }
}
