import time
import random
from datetime import datetime
import secrets


def generate_id() -> str:
    """Generate a time-sortable unique ID (simplified ULID-style)."""
    timestamp = int(time.time() * 1000)
    randomness = random.randint(0, 0xFFFFFF)
    return f"{timestamp:013x}{randomness:06x}"


def generate_order_no() -> str:
    """Generate a human-readable order number with yyyymmddhhmmss format."""
    # 格式化为 yyyymmddhhmmss 格式的时间戳
    now = datetime.now()
    timestamp = now.strftime("%Y%m%d%H%M%S")
    # 使用密码学安全的随机数生成 8位纯数字，防止并发冲突
    random_part = ''.join(str(secrets.randbelow(10)) for _ in range(8))
    return f"MZZC{timestamp}{random_part}"
