from decimal import Decimal

from app.services.commission_service import CommissionService
from app.services.search_service import SearchService
from app.utils.helpers import build_whatsapp_url, update_payment_summary


def test_update_payment_summary_paid():
    pending, paid, status = update_payment_summary(Decimal("1000"), Decimal("1000"))
    assert pending == Decimal("0.00")
    assert status.value == "paid"


def test_update_payment_summary_partial():
    pending, paid, status = update_payment_summary(Decimal("1000"), Decimal("250"))
    assert pending == Decimal("750")
    assert status.value == "partial"


def test_build_whatsapp_url_indian_mobile():
    url = build_whatsapp_url("9876543210", "Hello")
    assert "919876543210" in url
    assert "Hello" in url or "text=" in url


def test_commission_percent_calculation():
    svc = CommissionService(db=None)
    rule_type = "percent"
    value = Decimal("10")
    premium = Decimal("5000")
    commission = premium * value / Decimal("100") if rule_type == "percent" else value
    assert commission == Decimal("500")


def test_search_requires_minimum_query():
    items, total = SearchService(db=None).search(1, "a")
    assert items == []
    assert total == 0
