import '../../marianumconnect_query.dart';

/// Sends a single client-side error report to MarianumConnect
/// (`POST client-errors`). The endpoint is public, so reports that happen
/// before login are still captured; when a bearer token is present the shared
/// dio interceptor attaches it and the server attributes the report to that user.
class ReportClientError extends MarianumConnectQuery {
  ReportClientError({super.dio});

  Future<void> run({
    required String errorType,
    String? message,
    String? stacktrace,
    String? context,
    String? platform,
    String? appVersion,
    String? deviceModel,
  }) => guard(() async {
    await dio.post<void>(
      endpoint('client-errors'),
      data: {
        'errorType': errorType,
        'message': ?message,
        'stacktrace': ?stacktrace,
        'context': ?context,
        'platform': ?platform,
        'appVersion': ?appVersion,
        'deviceModel': ?deviceModel,
      },
    );
  });
}
