/// Configurazione globale dell'app Match Live TV.
class AppConfig {
  AppConfig._();

  /// URL base API Rails. Default emulatore Android → host localhost.
  static const String apiBaseUrl = String.fromEnvironment(
    'API_BASE_URL',
    defaultValue: 'http://10.0.2.2:3000',
  );

  static String get apiV1 => '$apiBaseUrl/api/v1';

  static String get cableUrl {
    final uri = Uri.parse(apiBaseUrl);
    final wsScheme = uri.scheme == 'https' ? 'wss' : 'ws';
    final defaultPort = uri.scheme == 'https' ? 443 : 80;
    final port = uri.hasPort ? uri.port : defaultPort;
    // Evita :443/:80 espliciti — alcuni client WebSocket/NPM li gestiscono male
    if (port == defaultPort) {
      return '$wsScheme://${uri.host}/cable';
    }
    return '$wsScheme://${uri.host}:$port/cable';
  }
}
