class ApiConfig {
  static const String host = '192.168.1.36';
  static const String port = '8000';

  static String get baseUrl {
    return 'http://$host:$port/api';
  }

  static Uri apiUri(String path) {
    final normalizedPath = path.replaceAll('\\', '/').replaceFirst(
          RegExp(r'^/+'),
          '',
        );
    return Uri.http('$host:$port', '/api/$normalizedPath');
  }

  static String get storageUrl {
    return 'http://$host:$port/storage/';
  }

  static String normalizeBackendUrl(String path) {
    final normalizedPath = path.replaceAll('\\', '/').trim();
    if (normalizedPath.isEmpty) return '';

    final uri = Uri.tryParse(normalizedPath);
    if (uri != null && uri.hasScheme) {
      return normalizedPath;
    }

    return normalizedPath;
  }
}
