import '../i18n/locale_utils.dart';

String? computeNullCheckRecoveryTarget({
  required Object exception,
  required Uri uri,
  required String preferredLocaleCode,
}) {
  final message = exception.toString();
  if (!message.contains('Null check operator used on a null value')) {
    return null;
  }

  final localeCode =
      extractLocaleFromPath(uri) ?? normalizeLocaleCode(preferredLocaleCode);
  final path = uri.path;
  final localeRootPath = '/$localeCode';
  if (path != '/' && path != localeRootPath) {
    return null;
  }

  final target = '/$localeCode/signin';
  if (path == target) {
    return null;
  }
  return target;
}
