class TmdbImageUrl {
  static String? profile(
    String imageBaseUrl,
    String? path, {
    String size = 'w185',
  }) {
    return _build(imageBaseUrl, path, size);
  }

  static String? poster(
    String imageBaseUrl,
    String? path, {
    String size = 'w500',
  }) {
    return _build(imageBaseUrl, path, size);
  }

  static String? backdrop(
    String imageBaseUrl,
    String? path, {
    String size = 'original',
  }) {
    return _build(imageBaseUrl, path, size);
  }

  static String? still(
    String imageBaseUrl,
    String? path, {
    String size = 'w300',
  }) {
    return _build(imageBaseUrl, path, size);
  }

  static String? logo(
    String imageBaseUrl,
    String? path, {
    String size = 'w500',
  }) {
    return _build(imageBaseUrl, path, size);
  }

  static String? _build(String imageBaseUrl, String? path, String size) {
    if (path == null || path.isEmpty) return null;
    final base = imageBaseUrl.endsWith('/')
        ? imageBaseUrl.substring(0, imageBaseUrl.length - 1)
        : imageBaseUrl;
    final normalizedPath = path.startsWith('/') ? path : '/$path';
    return '$base/$size$normalizedPath';
  }
}
