import 'dart:convert';

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

final Logger _log = Logger('statistics.dart');

class Statistics {
  static String get eventUri => 'https://pcoloring.com/napi/event/v2';

  static postEvent(Map data) async {
    try {
      _log.info(jsonEncode(data));
      final response = await http.post(
        Uri.parse(eventUri),
        headers: <String, String>{
          'Content-Type': 'application/json; charset=UTF-8',
        },
        body: jsonEncode(data),
      );
      if (response.statusCode != 200) {
        // throw Exception('Invalid status code: ${response.statusCode} when post event to: $eventUri');
        _log.info('Invalid status code: ${response.statusCode} when post event to: $eventUri');
      }
      _log.info('${response.statusCode}, $eventUri');
    } catch (error) {
      _log.info('$error');
    }
  }
}
