const PURCHASE_ORDER_LOCK_TIMEOUT_MS = 30 * 60 * 1000;

export function isPurchaseOrderLockActive(lock: {
  lockedById?: string;
  lockedAt?: string;
} | null | undefined): boolean {
  if (!lock?.lockedById) return false;

  const lockedAtValue = String(lock.lockedAt || '').trim();
  if (!lockedAtValue) return true;

  const lockedAtTime = Date.parse(lockedAtValue);
  if (!Number.isFinite(lockedAtTime)) return true;

  return Date.now() - lockedAtTime < PURCHASE_ORDER_LOCK_TIMEOUT_MS;
}
