"""日结模块信号处理函数"""
import logging

from .models import NotificationChannelEnum

logger = logging.getLogger(__name__)


def on_daily_settlement_completed(sender, **kwargs):
    """日结完成时的处理（日志输出）"""
    merchant = kwargs.get('merchant')
    settlement_date = kwargs.get('settlement_date')
    status = kwargs.get('status')
    modules = kwargs.get('modules', [])
    errors = kwargs.get('errors', {})
    task_id = kwargs.get('task_id')
    
    # 检查配置是否启用通知
    config = merchant.settlement_config
    if not config or not config.notification_enabled:
        logger.info(
            f'[settlement.handlers] 商户 {merchant.id} 日结完成，通知未启用'
        )
        return
    
    # 根据通知渠道处理（目前只有企业微信）
    if config.notification_channel == NotificationChannelEnum.WECOM:
        logger.info(
            f'[settlement.handlers] 商户 {merchant.id} 日结完成，'
            f'状态={status}, 模块={modules}, 错误={errors}, '
            f'通知渠道=企业微信（暂不发送具体内容）'
        )
