const IGNORED_DIRS = new Set([
    'node_modules', '.git', '.vscode', '.idea', 'dist', 'build', '.cache',
]);
function detectPlatform(remoteUrl) {
    if (!remoteUrl)
        return null;
    const lower = remoteUrl.toLowerCase();
    if (lower.includes('gitlab'))
        return 'gitlab';
    if (lower.includes('github'))
        return 'github';
    return null;
}
export class DiscoverRepositoriesUseCase {
    deps;
    constructor(deps) {
        this.deps = deps;
    }
    execute(input) {
        const repositories = [];
        const scannedPaths = [];
        const skippedPaths = [];
        for (const scanPath of input.scanPaths) {
            if (!this.deps.existsSync(scanPath)) {
                skippedPaths.push(scanPath);
                continue;
            }
            scannedPaths.push(scanPath);
            this.scan(scanPath, 0, input.maxDepth, repositories);
        }
        return { repositories, scannedPaths, skippedPaths };
    }
    scan(dirPath, currentDepth, maxDepth, results) {
        if (currentDepth >= maxDepth)
            return;
        let entries;
        try {
            entries = this.deps.readdirSync(dirPath);
        }
        catch {
            return;
        }
        for (const entry of entries) {
            if (!entry.isDirectory())
                continue;
            if (entry.name.startsWith('.') || IGNORED_DIRS.has(entry.name))
                continue;
            const fullPath = `${dirPath}/${entry.name}`;
            const gitPath = `${fullPath}/.git`;
            if (this.deps.existsSync(gitPath)) {
                const remoteUrl = this.deps.getGitRemoteUrl(fullPath);
                const reviewConfigPath = `${fullPath}/.claude/reviews/config.json`;
                results.push({
                    name: entry.name,
                    localPath: fullPath,
                    platform: detectPlatform(remoteUrl),
                    remoteUrl,
                    hasReviewConfig: this.deps.existsSync(reviewConfigPath),
                });
            }
            else {
                this.scan(fullPath, currentDepth + 1, maxDepth, results);
            }
        }
    }
}
//# sourceMappingURL=discoverRepositories.usecase.js.map