function buildRepositoryPathCandidates(filePath, previousFilePath) {
    const candidates = [filePath, previousFilePath ?? null]
        .filter((value) => typeof value === 'string' && value.trim().length > 0);
    return Array.from(new Set(candidates));
}
export function reconcileWithScmSnapshot(params) {
    const entries = params.snapshot?.entries ?? [];
    const consumedPaths = new Set();
    const matchedFiles = [];
    const unmatchedSessionFiles = [];
    for (const sessionFile of params.sessionChangeSet.files) {
        const candidates = buildRepositoryPathCandidates(sessionFile.filePath, sessionFile.previousFilePath);
        const match = entries.find((entry) => candidates.includes(entry.path) || (entry.previousPath ? candidates.includes(entry.previousPath) : false));
        if (!match) {
            unmatchedSessionFiles.push(sessionFile);
            continue;
        }
        consumedPaths.add(match.path);
        matchedFiles.push({
            filePath: sessionFile.filePath,
            repositoryPath: match.path,
            sessionChange: sessionFile,
            repositoryEntry: {
                path: match.path,
                previousPath: match.previousPath,
                kind: match.kind,
            },
        });
    }
    const repositoryOnlyFiles = entries
        .filter((entry) => !consumedPaths.has(entry.path))
        .map((entry) => ({
        path: entry.path,
        previousPath: entry.previousPath,
        kind: entry.kind,
    }));
    return {
        sessionId: params.sessionChangeSet.sessionId,
        matchedFiles,
        unmatchedSessionFiles,
        repositoryOnlyFiles,
        projectionReliability: params.sessionChangeSet.confidenceSummary.confidence,
    };
}
//# sourceMappingURL=reconcileWithScmSnapshot.js.map