<?php
// api/presenters/podcast-presenters.php
require_once '../../config/cors.php';
require_once '../../config/db.php';
require_once '../../config/r2.php';
require_once '../../helpers/response.php';

$podcast_id = $_GET['podcast_id'] ?? null;

if (!$podcast_id) {
    sendError('Podcast ID required', 400);
}

try {
    $stmt = $pdo->prepare("
        SELECT pp.*, p.name, p.image
        FROM podcast_presenters pp
        JOIN presenters p ON p.id = pp.presenter_id
        WHERE pp.podcast_id = ?
    ");
    $stmt->execute([$podcast_id]);
    $presenters = $stmt->fetchAll();
    

    foreach ($presenters as &$presenter) {
        if ($presenter['image']) {
            $presenter['image_url'] = R2_PUBLIC_URL . '/' . $presenter['image'];
        }
    }
    
    sendSuccess($presenters);
    
} catch (PDOException $e) {
    sendError('Database error: ' . $e->getMessage(), 500);
}
?>