<?php
require_once '../../config/cors.php';
require_once '../../config/db.php';
require_once '../../helpers/response.php';
require_once '../../helpers/auth.php';

$admin = requireAdmin();
$stream_id = $_GET['stream_id'] ?? null;

if (!$stream_id) {
    sendError('Stream ID required', 400);
}

// Get admin replies
$stmt = $pdo->prepare("
    SELECT cm.id, cm.message, cm.created_at, cm.parent_id, u.name as admin_name
    FROM chat_messages cm
    JOIN users u ON u.id = cm.admin_id
    WHERE cm.stream_id = ? AND cm.user_type = 'admin' AND cm.parent_id IS NOT NULL
    ORDER BY cm.created_at ASC
");
$stmt->execute([$stream_id]);
$replies = $stmt->fetchAll();

sendSuccess($replies);
?>