from types import SimpleNamespace

from app_new.core.models.maintenance import LotTask
from app_new.contracts.models import Contract  # noqa: F401 - enregistre la relation ORM
from app_new.core.preventive_duration_proposals import PROPOSED_UNIT_DURATIONS


def test_duration_is_per_element_and_group_quantity():
    task = LotTask(duree_minutes=2, duration_mode="unit")
    assert task.duration_for_equipment(SimpleNamespace(quantity=10)) == 20
    assert task.duration_for_equipment(SimpleNamespace(quantity=1)) == 2


def test_missing_duration_is_explicitly_unplannable():
    task = LotTask(duree_minutes=None, duration_mode="unit")
    assert task.duration_is_configured is False
    assert task.duration_for_equipment(SimpleNamespace(quantity=10)) == 0


def test_fixed_duration_does_not_multiply_quantity():
    task = LotTask(duree_minutes=30, duration_mode="fixed")
    assert task.duration_for_equipment(SimpleNamespace(quantity=10)) == 30


def test_duration_proposals_are_explicit_and_not_historical_fallbacks():
    assert len(PROPOSED_UNIT_DURATIONS) == 132
    assert all(value > 0 for value in PROPOSED_UNIT_DURATIONS.values())
