<?php
/**
 * GET /api/rewards/redemptions.php
 * The caller's own claimed-reward history.
 */

require_once __DIR__ . '/../config/database.php';
require_once __DIR__ . '/../includes/response.php';
require_once __DIR__ . '/../includes/auth.php';

$userId = require_login();
$pdo = Database::connect();

$stmt = $pdo->prepare('
    SELECT rr.id, rr.points_spent, rr.redemption_code, rr.status, rr.created_at, r.title
    FROM reward_redemptions rr
    JOIN rewards r ON r.id = rr.reward_id
    WHERE rr.user_id = ?
    ORDER BY rr.created_at DESC
');
$stmt->execute([$userId]);

send_json(true, 'OK', ['redemptions' => $stmt->fetchAll()]);
