<?php
require_once 'config.php';

if (!isset($_SESSION['user_id'])) response(["error" => "No autorizado"], 401);

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

if (!isset($data['title']) || !isset($data['content'])) {
    response(["error" => "Datos incompletos"], 400);
}

try {
    $stmt = $pdo->prepare("INSERT INTO announcements (title, content, author_id, priority, status) VALUES (?, ?, ?, ?, ?)");
    $stmt->execute([
        $data['title'],
        $data['content'],
        $_SESSION['user_id'],
        $data['priority'] ?? 'Media',
        $data['status'] ?? 'Pendiente'
    ]);
    response(["success" => true]);
} catch (PDOException $e) {
    response(["error" => $e->getMessage()], 500);
}
?>