from fastapi import HTTPException


async def assert_updateable(sf, sobject: str, field: str):
    """Assert that a given field on an sObject is updateable by the current connection.

    Uses the gateway's describe() to fetch field metadata and checks the 'updateable' flag.
    Raises HTTPException 400 if the field is not updateable.
    """
    desc = await sf.describe(sobject)
    fmap = {f.get("name"): f for f in (desc or {}).get("fields", [])}
    if field not in fmap or not fmap[field].get("updateable", False):
        raise HTTPException(400, f"{sobject}.{field} not updateable by this connection")
