import 'package:http/http.dart' as http;
import 'package:shared_preferences/shared_preferences.dart';

class ApiClient {
  static final ApiClient instance = ApiClient('http://10.0.2.2:5032/api');
  final String _baseUrl;

  ApiClient(this._baseUrl);

  Future<http.Response> get(String endpoint) async {
    final prefs = await SharedPreferences.getInstance();
    final token = prefs.getString('auth_token');

    if (token == null) {
      throw Exception('No token found. User might not be logged in.');
    }

    final url = '$_baseUrl/$endpoint';
    print("Url received: $url");
    final headers = {
      'Authorization': 'Bearer $token',
      'Content-Type': 'application/json',
    };

    return await http.get(Uri.parse(url), headers: headers);
  }
}

