from __future__ import annotations

import secrets
import string
import time

import httpx

from . import settings


def random_password(length: int = 32) -> str:
    alphabet = string.ascii_letters + string.digits
    return "".join(secrets.choice(alphabet) for _ in range(length))


def best_effort_post(url: str) -> None:
    if not url:
        return
    try:
        with httpx.Client(timeout=settings.HTTP_CHECK_TIMEOUT_SEC) as client:
            client.post(url, json={"ts": int(time.time())})
    except Exception:
        return

