import 'dart:async';
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:lgcc/models/item_model.dart';

class DirectusService {

Future<List<dynamic>> getConferences() async {
  final String baseUrl = dotenv.env['DIRECTUS_API_URL']!;
    final response = await http.get(
      Uri.parse('$baseUrl/items/conferences?fields=*,translations.markdown&access_token=${dotenv.env['DIRECTUS_API_TOKEN']}'),
    );
    assert(() {
      print('Response status code: ${response.statusCode}');
      return true;
    }());
    if (response.statusCode == 200) {
      final data = jsonDecode(response.body)['data'];
      return data.map((item) => ItemModel.fromJson(item)).toList();
    } else {
      throw Exception('Failed to load conferences');
    }
  }
}