export function rankCatalogVotes(votes, options) {
    return votes
        .map((vote) => {
        const artifactId = options.artifactId(vote);
        const artifactClass = options.classify(vote);
        const eligibility = options.eligible({ ...vote, artifactClass });
        const historyScore = options.historyScore(artifactId);
        return {
            ...vote,
            artifactClass,
            history: options.historyRecord(artifactId),
            score: vote.score + historyScore,
            eligible: eligibility.eligible,
            blockedReason: eligibility.blockedReason,
            reasons: historyScore
                ? [...vote.reasons, `Historical effectiveness adjusted score by ${historyScore.toFixed(2)}.`]
                : vote.reasons,
        };
    })
        .sort((left, right) => right.score - left.score
        || options.sourcePrecedence(left.source) - options.sourcePrecedence(right.source)
        || options.artifactName(left).localeCompare(options.artifactName(right)));
}
export function splitCatalogVotes(ranked, options) {
    const selected = ranked
        .filter((entry) => options.isSelected(entry))
        .slice(0, options.limit);
    const rejected = ranked
        .filter((entry) => !selected.some((candidate) => candidate.value === entry.value))
        .slice(0, options.rejectLimit ?? 8);
    return { selected, rejected };
}
