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

class TextClassificationService {
  Future<int> classifyText(String text) async {
    try {
      final uri = Uri.parse('http://143.64.185.20:18606/classify');

      final response = await http.post(
        uri,
        headers: {'Content-Type': 'application/json'},
        body: json.encode({'text': text}),
      );

      if (response.statusCode == 200) {
        return json.decode(response.body)['category'];
      } else {
        print(
            'Classification failed: ${response.statusCode}, ${response.body}');
        return -1;
      }
    } catch (e) {
      print('Error during text classification: $e');
      return -1;
    }
  }
}
