"""Action audit logging."""
import logging
logger = logging.getLogger(__name__)

async def log(context, chat_id, action, actor_id=0, target_id=0, extra=""):
    try:
        from bot.config import LOG_CHANNEL
        if LOG_CHANNEL:
            text = f"<b>{action}</b>\nChat: <code>{chat_id}</code>\nActor: <code>{actor_id}</code>\nTarget: <code>{target_id}</code>"
            if extra:
                text += f"\n{extra}"
            await context.bot.send_message(chat_id=LOG_CHANNEL, text=text, parse_mode="HTML")
    except Exception as e:
        logger.warning("Audit log failed: %s", e, exc_info=True)

def register(app):
    logger.debug("Audit middleware initialized")
