import os
import httpx

from ..auth import auth_headers


async def log_product_result(
        ok: bool,
        payload
):

    sync_url = os.getenv("PRODUCT_LOG_URL", "http://localhost:8000/market/api/products/log/")

    async with httpx.AsyncClient(timeout=httpx.Timeout(20.0, connect=10.0)) as client:
        _d = {
            "ok": ok,
            "payload": payload
        }
        resp = await client.post(sync_url, json=_d, headers=auth_headers())
    # Raise for non-2xx
    resp.raise_for_status()
    data = resp.json() if resp.content else {}
    return data
    