from __future__ import annotations

from app.market.models import CandidateRecord, InquiryRequest


def rejection_reasons(candidate: CandidateRecord, inquiry: InquiryRequest) -> list[str]:
    reasons: list[str] = []

    if candidate.origin != inquiry.origin or candidate.destination != inquiry.destination:
        reasons.append("起运地或目的地不匹配")
    if not candidate.supplier_active:
        reasons.append("供应商不是有效合作方")
    if not candidate.capacity_available:
        reasons.append("当前班期没有可用运力")
    if candidate.valid_from and inquiry.evaluation_date < candidate.valid_from:
        reasons.append(f"报价尚未生效（{candidate.valid_from.isoformat()}起）")
    if candidate.valid_to and inquiry.evaluation_date > candidate.valid_to:
        reasons.append(f"报价已于{candidate.valid_to.isoformat()}失效")
    if not candidate.departure_date:
        reasons.append("报价没有关联可执行班期")
    elif candidate.departure_date < inquiry.requested_departure_date:
        reasons.append(f"班期{candidate.departure_date.isoformat()}早于要求起运日")
    if candidate.transit_days > inquiry.max_transit_days:
        reasons.append(
            f"预计{candidate.transit_days:g}天，超过客户{inquiry.max_transit_days:g}天上限"
        )
    if inquiry.dangerous_goods and not candidate.supports_dangerous_goods:
        reasons.append("该供应商产品关系不支持危险品")
    if not inquiry.dangerous_goods and candidate.dangerous_goods_only:
        reasons.append("危险品专用产品不适用于普通货物")

    return reasons
