<?php
declare(strict_types=1);

/**
 * TechStackBase – Legal Hold Guard
 *
 * Legal hold is a global safety lock.
 * If enabled, destructive operations are blocked.
 *
 * Fails SAFE (disabled) if misconfigured.
 */

function legal_hold_enabled(PDO $pdo): bool
{
    try {
        $stmt = $pdo->query("
            SELECT enabled
            FROM legal_hold
            ORDER BY id ASC
            LIMIT 1
        ");

        $value = $stmt->fetchColumn();

        // Explicit check — only 1 / true enables legal hold
        return $value === 1 || $value === '1';

    } catch (Throwable $e) {
        // IMPORTANT:
        // If legal_hold table is missing or broken,
        // we FAIL OPEN to avoid locking the platform.
        return false;
    }
}
