from extractly.models import AdsManual
from houslyspace.models import AdsInactiveSync


def _mark_sent_by_urls(urls: set[str]) -> None:
    if not urls:
        return
    AdsManual.objects.filter(url__in=list(urls)).update(isSendToMainServer=True)
    




from django.utils import timezone

def _mark_inactive_sent(bunch: list[tuple[AdsManual, dict, str]]):
    if not bunch:
        return
    now = timezone.now()
    for ad, _payload, h in bunch:
        sync, _ = AdsInactiveSync.objects.get_or_create(ad=ad)
        sync.last_inactive_value = ad.inactive_date
        sync.last_payload_hash = h
        sync.last_error = None
        sync.attempts = 0
        sync.last_sent_at = now
        sync.save(update_fields=[
            "last_inactive_value", "last_payload_hash",
            "last_error", "attempts", "last_sent_at", "updated_at"
        ])
