import 'package:flutter/widgets.dart';

import '../l10n/l10n.dart';
import 'api_exception.dart';

String mapErrorToUserMessage(Object error, BuildContext context) {
  final l10n = context.l10n;
  if (error is ApiException) {
    switch (error.type) {
      case ApiErrorType.unauthorized:
        return l10n.sessionExpiredError;
      case ApiErrorType.forbidden:
        return l10n.forbiddenError;
      case ApiErrorType.server:
        return l10n.serverError;
      case ApiErrorType.network:
        return l10n.networkError;
      case ApiErrorType.unknown:
        return error.message.isNotEmpty ? error.message : l10n.unexpectedError;
    }
  }
  return l10n.unexpectedError;
}
