package top.r3944realms.docchecktoolrefactored.test;

import lombok.extern.slf4j.Slf4j;
import top.r3944realms.docchecktoolrefactored.core.DuplicateFinder;
import top.r3944realms.docchecktoolrefactored.core.FileHashCalculator;
import top.r3944realms.docchecktoolrefactored.io.scanner.FileScanner;
import top.r3944realms.docchecktoolrefactored.io.scanner.RobustParallelScanner;
import top.r3944realms.docchecktoolrefactored.model.DuplicateGroup;

import java.io.IOException;
import java.nio.file.Paths;
import java.util.List;

@Slf4j
public class DuplicateTest {
    public static void main(String[] args) throws IOException {
        // 创建组件
        FileScanner scanner1 = new RobustParallelScanner(20);
        FileHashCalculator hashCalculator1 = FileHashCalculator.defaultInstance();
        FileScanner scanner2 = new RobustParallelScanner(20);
        FileHashCalculator hashCalculator2 = FileHashCalculator.defaultInstance();

        // 执行查重
        DuplicateFinder finder = new DuplicateFinder(scanner1, hashCalculator1);
        DuplicateFinder finder2 = new DuplicateFinder(scanner2, hashCalculator2, true);
        List<DuplicateGroup> duplicates = finder.findDuplicates(Paths.get("H:\\nw0\\newworld(1)(1)"));

        // 处理结果
        duplicates.forEach(group -> {
            log.info("发现重复文件组({} bytes):", group.size());
            group.fileMetas().forEach(file ->
                    log.info("  {}", file.getPath())
            );
        });
    }
}
