/**
 * Task size weighting and priority scoring.
 * Ported from lib/tasks/size-weighting.sh
 *
 * @epic T4454
 * @task T4529
 */
/** Size weight multipliers. */
const SIZE_WEIGHTS = {
    small: 1,
    medium: 3,
    large: 8,
};
/** Priority weight multipliers. */
const PRIORITY_WEIGHTS = {
    critical: 10,
    high: 5,
    medium: 2,
    low: 1,
};
/**
 * Get weight for a task size.
 */
export function getSizeWeight(size) {
    return SIZE_WEIGHTS[size ?? 'medium'] ?? SIZE_WEIGHTS.medium;
}
/**
 * Get weight for a task priority.
 */
export function getPriorityWeight(priority) {
    return PRIORITY_WEIGHTS[priority] ?? PRIORITY_WEIGHTS.medium;
}
/**
 * Calculate a composite score for task ordering.
 * Higher score = should be worked on first.
 */
export function calculateTaskScore(task) {
    const sizeW = getSizeWeight(task.size);
    const priorityW = getPriorityWeight(task.priority);
    // Base score from priority (dominant factor)
    let score = priorityW * 10;
    // Bonus for smaller tasks (quick wins with same priority)
    score += (8 - sizeW) * 2;
    // Active status bonus
    if (task.status === 'active')
        score += 50;
    // Blocked penalty
    if (task.status === 'blocked')
        score -= 20;
    return score;
}
/**
 * Sort tasks by weighted score (highest first).
 */
export function sortByWeight(tasks) {
    return [...tasks].sort((a, b) => calculateTaskScore(b) - calculateTaskScore(a));
}
/**
 * Calculate total weighted effort for a set of tasks.
 */
export function calculateTotalEffort(tasks) {
    return tasks.reduce((total, t) => total + getSizeWeight(t.size), 0);
}
/**
 * Calculate completion percentage by weight.
 */
export function calculateWeightedProgress(tasks) {
    if (tasks.length === 0)
        return 0;
    const total = calculateTotalEffort(tasks);
    if (total === 0)
        return 0;
    const completed = tasks
        .filter((t) => t.status === 'done' || t.status === 'cancelled')
        .reduce((sum, t) => sum + getSizeWeight(t.size), 0);
    return Math.round((completed / total) * 100);
}
/**
 * Estimate remaining effort (weighted sum of non-complete tasks).
 */
export function calculateRemainingEffort(tasks) {
    return tasks
        .filter((t) => t.status !== 'done' && t.status !== 'cancelled')
        .reduce((sum, t) => sum + getSizeWeight(t.size), 0);
}
//# sourceMappingURL=size-weighting.js.map