import 'dart:io';
import 'package:image/image.dart' as img;

/// Jalankan dengan: dart run tool/generate_notification_icon.dart
void main() async {
  final inputPath = 'assets/images/logo_white.png';
  final outputBase = 'android/app/src/main/res';

  final sizes = {
    'drawable-mdpi': 24,
    'drawable-hdpi': 36,
    'drawable-xhdpi': 48,
    'drawable-xxhdpi': 72,
    'drawable-xxxhdpi': 96,
  };

  final inputFile = File(inputPath);
  if (!inputFile.existsSync()) {
    print('ERROR: File tidak ditemukan: $inputPath');
    exit(1);
  }

  final originalBytes = inputFile.readAsBytesSync();
  final original = img.decodeImage(originalBytes);
  if (original == null) {
    print('ERROR: Gagal decode image');
    exit(1);
  }

  print('Source: $inputPath (${original.width}x${original.height})');

  for (final entry in sizes.entries) {
    final folder = '$outputBase/${entry.key}';
    final outputPath = '$folder/ic_notification.png';

    Directory(folder).createSync(recursive: true);

    final size = entry.value;
    final resized = img.copyResize(original, width: size, height: size);
    final pngBytes = img.encodePng(resized);

    File(outputPath).writeAsBytesSync(pngBytes);
    print('Generated: $outputPath (${size}x${size})');
  }

  print('\nDone! Gunakan icon: "ic_notification" di fcm_service.dart');
}
