import json
from datetime import datetime
from typing import Any


def now_ts() -> str:
    return datetime.now().strftime('%Y-%m-%d %H:%M:%S')


def build_trace_id(acc_id: str, customer_id: str, msg: str) -> str:
    base = f"{acc_id}|{customer_id}|{msg}|{now_ts()}"
    return hex(abs(hash(base)))[2:18]


def activity_event(logger, event: str, *, trace_id: str = '-', customer_id: str = '-', result: str = 'ok', **kwargs: Any) -> None:
    payload = {
        'trace_id': trace_id or '-',
        'customer_id': customer_id or '-',
        'event': event,
        'result': result,
        **kwargs,
    }
    logger.info('[活动日志] %s', json.dumps(payload, ensure_ascii=False))
