from __future__ import annotations

from api.models.suggestion import Suggestion


def cost_of_delay(suggestion: Suggestion) -> float:
    return suggestion.base_value + (suggestion.relevance_weight * suggestion.relevance)


def compute_wsjf(suggestion: Suggestion) -> float:
    size = suggestion.job_size if suggestion.job_size > 0 else 3.0
    return round(cost_of_delay(suggestion) / size, 2)


def suggestion_sort_key(suggestion: Suggestion) -> tuple[float, int, str]:
    """Higher WSJF first; tie-break on relevance then title."""
    return (-compute_wsjf(suggestion), -suggestion.relevance, suggestion.title.lower())