"""资金冻结相关 Celery 定时任务。"""
import logging

from celery import shared_task

logger = logging.getLogger(__name__)


@shared_task(name='jituan.tasks.scan_fund_freeze_due')
def scan_fund_freeze_due(limit: int = 200):
    """扫到期冻结单，按配置执行一步解冻（未开冻结的俱乐部无数据，空跑）。"""
    from jituan.services.fund_freeze import scan_due_freeze_ledgers
    result = scan_due_freeze_ledgers(limit=limit)
    logger.info('scan_fund_freeze_due %s', result)
    return result


@shared_task(name='jituan.tasks.scan_order_auto_settle_due')
def scan_order_auto_settle_due(limit: int = 100):
    """
    可控自动结算：仅 Status=8 且 AutoSettleEligible 且 AutoExpireAt 到期。
    俱乐部开关关闭时空跑；绝不扫老结算中单。
    """
    from jituan.services.order_deal import scan_due_auto_settle
    result = scan_due_auto_settle(limit=limit)
    logger.info('scan_order_auto_settle_due %s', result)
    return result
