<?php
require_once "../../includes/db.php";
header('Content-Type: application/json');

$id = $_POST['id'] ?? 0;

$stmt = $pdo->prepare("
    SELECT 
        p.pm_id,
        p.user_id,
        CONCAT(u.firstname,' ', u.secondname) As name,
        c.acc_name,
         p.pm_acc_categ,
        CASE
            WHEN p.pm_acc_lvl = 0 THEN 'View only'
            WHEN p.pm_acc_lvl = 1 THEN 'View & Confirm'
            WHEN p.pm_acc_lvl = 2 THEN 'View & Transfer to Account'
            WHEN p.pm_acc_lvl = 3 THEN 'View & Transfer from Account'
            WHEN p.pm_acc_lvl = 4 THEN 'View,Transfer to & from Account'
            WHEN p.pm_acc_lvl = 5 THEN 'View,confirm,Transfer to & from Account'
            WHEN p.pm_acc_lvl = 6 THEN 'View & Approve Transactions'
            WHEN p.pm_acc_lvl = 7 THEN 'All access'
        END AS permission_level
    FROM permissions p
JOIN users u ON p.user_id = u.id
LEFT JOIN accounts c ON c.id = p.pm_acc_id
    WHERE p.pm_id = ?
");

$stmt->execute([$id]);
echo json_encode($stmt->fetch(PDO::FETCH_ASSOC));
exit;