class AppH5Urls {
  const AppH5Urls._();

  static const baseUrl = String.fromEnvironment(
    'JINZHI_H5_BASE_URL',
    defaultValue: 'https://jinzhi.h5.local',
  );

  static String get privacyUrl => '$baseUrl/beginner/privacyPolicy.html';
  static String get userProtocolUrl => '$baseUrl/beginner/user_agreement.html';
}

class AppH5UrlsHelper {
  const AppH5UrlsHelper._();

  static String buildUrl(String url, [Map<String, dynamic>? params]) {
    if (params == null || params.isEmpty) return url;
    final uri = Uri.parse(url);
    final merged = <String, String>{
      ...uri.queryParameters,
      ...params.map((key, value) => MapEntry(key, value.toString())),
    };
    return uri.replace(queryParameters: merged).toString();
  }

  static String buildUrlWithNight(String url, bool isDark) {
    if (!isDark) return url;
    return buildUrl(url, {'isNight': '1'});
  }

  static String withCacheBuster(String url) {
    final uri = Uri.parse(url);
    final params = Map<String, String>.from(uri.queryParameters);
    params['_cb'] = DateTime.now().microsecondsSinceEpoch.toString();
    return uri.replace(queryParameters: params).toString();
  }
}
