
import asyncio
from typing import Dict, Tuple

_locks: Dict[Tuple[str, str], asyncio.Lock] = {}

def _key(account_id: str, object_type: str) -> Tuple[str, str]:
    # normalize once; supports enums and mixed case
    return (str(account_id), str(object_type).split(".")[-1].lower())

def get_lock(account_id: str, object_type: str) -> asyncio.Lock:
    """
    Return a per-(account_id, object_type) asyncio.Lock.
    
    TODO: For multi-worker/pod deployments, migrate to:
      - Redis distributed locks (redis.lock.Lock)
      - PostgreSQL advisory locks (pg_advisory_lock)
      - DynamoDB conditional writes
    Current implementation is safe for single-process pilots.
    """
    key = _key(account_id, object_type)
    # avoid races / double creation
    lock = _locks.get(key)
    if lock is None:
        lock = _locks.setdefault(key, asyncio.Lock())
    return lock
