<?php
// public/api/debug_groups.php
require_once '../../config.php';
require_once '../../functions.php';

header('Content-Type: application/json');

$response = [];

try {
    // All Groups
    $all = $pdo->query("SELECT id, name, owner_type, owner_id, status FROM contact_groups")->fetchAll(PDO::FETCH_ASSOC);
    $response['all_groups_in_db'] = $all;

    // Admin Query (Simulated)
    $adminQ = $pdo->query("SELECT id, name FROM contact_groups WHERE status = 'active'")->fetchAll(PDO::FETCH_ASSOC);
    $response['admin_view_groups'] = $adminQ;

    // User Query (Simulated for user_id = 1, adjust as needed)
    // Assuming typical test user ID is 1 or from session if available
    /*
    $userQ = $pdo->query("SELECT id, name FROM contact_groups WHERE owner_type = 'user' AND status = 'active'")->fetchAll(PDO::FETCH_ASSOC);
    $response['user_view_groups_generic'] = $userQ;
    */

} catch (Exception $e) {
    $response['error'] = $e->getMessage();
}

echo json_encode($response, JSON_PRETTY_PRINT);
