"""SP3b marketplace Celery tasks.

Schedule via Celery beat:
  * ``close_expired_demand_listings`` — daily, closes OPEN demand listings
    whose deadline has passed (audit fix; previously expired listings
    silently kept accepting responses).
"""
from __future__ import annotations

import logging

from celery import shared_task

logger = logging.getLogger(__name__)


@shared_task(name="smehub.marketplace.close_expired_demand_listings")
def close_expired_demand_listings_task() -> int:
    from apps.smehub.marketplace.services import close_expired_demand_listings

    count = close_expired_demand_listings()
    if count:
        logger.info("smehub.marketplace.close_expired_demand_listings closed %s listings", count)
    return count
