import 'models.dart';

String? resolveLinkedRpLaunchUrl(LinkedRp rp) {
  final normalizedStatus = rp.status.trim().toLowerCase();
  final isActive = normalizedStatus.isEmpty || normalizedStatus == 'active';
  if (!isActive) {
    return null;
  }

  if (rp.autoLoginSupported) {
    final autoLoginUrl = rp.autoLoginUrl.trim();
    if (autoLoginUrl.isNotEmpty) {
      return autoLoginUrl;
    }
    final initUrl = rp.initUrl.trim();
    if (initUrl.isNotEmpty) {
      return initUrl;
    }
  }

  final url = rp.url.trim();
  if (url.isNotEmpty) {
    return url;
  }

  return null;
}
