<?php

if (!function_exists('og_get_account_suspension')) {
    function og_get_account_suspension(PDO $pdo, int $userId): array
    {
        if ($userId <= 0) {
            return [
                'is_suspended' => false,
                'reason' => '',
                'suspended_until' => null,
            ];
        }

        try {
            $stmt = $pdo->prepare('SELECT account_suspended, suspension_reason, suspended_until FROM users WHERE id = ? LIMIT 1');
            $stmt->execute([$userId]);
            $row = $stmt->fetch(PDO::FETCH_ASSOC) ?: [];

            return [
                'is_suspended' => ((int)($row['account_suspended'] ?? 0) === 1),
                'reason' => trim((string)($row['suspension_reason'] ?? '')),
                'suspended_until' => $row['suspended_until'] ?? null,
            ];
        } catch (Throwable $e) {
            return [
                'is_suspended' => false,
                'reason' => '',
                'suspended_until' => null,
            ];
        }
    }
}

if (!function_exists('og_is_current_user_suspended')) {
    function og_is_current_user_suspended(PDO $pdo): array
    {
        $userId = (int)($_SESSION['user_id'] ?? 0);
        return og_get_account_suspension($pdo, $userId);
    }
}
