<?php
/**
 * GET /api/loyalty/balance.php
 */

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 points_balance FROM loyalty_points WHERE user_id = ?');
$stmt->execute([$userId]);
$row = $stmt->fetch();

send_json(true, 'OK', ['points_balance' => $row ? (int) $row['points_balance'] : 0]);
