import 'dart:io';

void main() async {
  final libDir = Directory('lib');
  if (!libDir.existsSync()) {
    print('No lib/ directory found.');
    return;
  }

  final dartFiles = libDir.listSync(recursive: true).whereType<File>().where((file) => file.path.endsWith('.dart')).toList();

  final allContent = StringBuffer();
  for (final file in dartFiles) {
    allContent.write(await file.readAsString());
  }

  final unusedFiles = <String>[];

  for (final file in dartFiles) {
    final filename = file.uri.pathSegments.last;
    final basename = filename.replaceAll('.dart', '');

    if (!allContent.toString().contains(basename) && !allContent.toString().contains(filename)) {
      unusedFiles.add(file.path);
    }
  }

  if (unusedFiles.isEmpty) {
    print('🎯 No unused files found!');
  } else {
    print('⚡️ Unused Dart files:${unusedFiles.length}');

    for (int i=0; i<unusedFiles.length; i++) {
      print('${i+1}- ${unusedFiles[i]}');
    }
  }
}
