import 'dart:io';

class AppConstants {
  static const String apiBaseUrlOverride =
      String.fromEnvironment('API_BASE_URL');
  static const String dashboardUrlOverride =
      String.fromEnvironment('DASHBOARD_URL');

  // Production
  static const String productionApiUrl = 'https://api.rentaldrivego.ma/api/v1';
  static const String productionDashboardUrl = 'https://rentaldrivego.ma/dashboard';

  // Development
  static const String devAndroidApiUrl = 'http://10.0.2.2:4000/api/v1';
  static const String devLocalApiUrl = 'http://localhost:4000/api/v1';
  static const String devAndroidDashboardUrl = 'http://10.0.2.2:3001';
  static const String devLocalDashboardUrl = 'http://localhost:3001';

  static String get baseUrl {
    if (apiBaseUrlOverride.isNotEmpty) return apiBaseUrlOverride;
    if (Platform.isAndroid) return devAndroidApiUrl;
    return devLocalApiUrl;
  }

  static String get dashboardBaseUrl {
    if (dashboardUrlOverride.isNotEmpty) return dashboardUrlOverride;
    if (Platform.isAndroid) return devAndroidDashboardUrl;
    return devLocalDashboardUrl;
  }

  static String resolveMediaUrl(String url) {
    if (!url.startsWith('http')) {
      return '${baseUrl.replaceAll('/api/v1', '')}$url';
    }
    if (Platform.isAndroid && url.contains('localhost')) {
      return url.replaceFirst('localhost', '10.0.2.2');
    }
    return url;
  }

  static const String tokenKey = 'auth_token';
  static const String userTypeKey = 'user_type';

  static const String userTypeEmployee = 'employee';
  static const String userTypeRenter = 'renter';
}
