<?php
require '../includes/conexao.php';
header('Content-Type: application/json');

// ADICIONADO 'id' na seleção para controle de duplicidade
$sql = "SELECT id, player_name, item_name, rarity 
        FROM gacha_history 
        WHERE rarity IN ('Epica', 'Lendaria', 'Mitica') 
        AND won_at > DATE_SUB(NOW(), INTERVAL 30 SECOND) 
        ORDER BY id DESC LIMIT 1";

$stmt = $pdo->query($sql);
$data = $stmt->fetch(PDO::FETCH_ASSOC);

if ($data) {
    echo json_encode(['has_notify' => true, 'data' => $data]);
} else {
    echo json_encode(['has_notify' => false]);
}
?>