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

$data = json_decode(file_get_contents('php://input'), true);

$target = $data['target_name'] ?? '';
$message = $data['message'] ?? '';
$dj_name = $data['dj_name'] ?? 'Lili';

if (empty($target) || empty($message)) {
    echo json_encode(['success' => false, 'error' => 'Target and message are required.']);
    exit;
}

try {
    $stmt = db()->prepare("INSERT INTO dj_shoutouts (target_fan_name, message, dj_name) VALUES (?, ?, ?)");
    $stmt->execute([$target, $message, $dj_name]);
    echo json_encode(['success' => true]);
} catch (Exception $e) {
    echo json_encode(['success' => false, 'error' => $e->getMessage()]);
}
