// Config/database_config.dart - Version améliorée
class DatabaseConfig {
 static const String host = '10.0.2.2';
  //static const String host = '172.20.10.5';
  // static const String host = 'localhost';
  static const int port = 3306;
  static const String username = 'root';
  static const String? password = null;
  static const String database = 'gico';

  static const String prodHost = '185.70.105.157';
  static const String prodUsername = 'guycom';
  static const String prodPassword = '3iV59wjRdbuXAPR';
  static const String prodDatabase = 'guycom';

  static const Duration connectionTimeout = Duration(seconds: 30);
  static const Duration queryTimeout = Duration(seconds: 15);

  static const int maxConnections = 10;
  static const int minConnections = 2;

  static bool get isDevelopment => true;

  static Map<String, dynamic> getConfig() {
    if (isDevelopment) {
      return {
        'host': host,
        'port': port,
        'user': username,
        'password': password,
        'database': database,
        'timeout': connectionTimeout.inSeconds,
      };
    } else {
      return {
        'host': prodHost,
        'port': port,
        'user': prodUsername,
        'password': prodPassword,
        'database': prodDatabase,
        'timeout': connectionTimeout.inSeconds,
      };
    }
  }

  // Validation de la configuration
  static bool validateConfig() {
    try {
      final config = getConfig();
      return config['host']?.toString().isNotEmpty == true && 
             config['database']?.toString().isNotEmpty == true && 
             config['user'] != null;
    } catch (e) {
      print("Erreur de validation de la configuration: $e");
      return false;
    }
  }

  // Configuration avec retry automatique
  static Map<String, dynamic> getConfigWithRetry() {
    final config = getConfig();
    config['retryCount'] = 3;
    config['retryDelay'] = 5000; // ms
    return config;
  }
}