<?php
/**
 * API: Get Loyalty Points Settings
 * Returns current loyalty points system configuration
 */

header('Content-Type: application/json');
session_start();
include_once('../../includes/config.php');

// Check if user is logged in
if (!isset($_SESSION['uid'])) {
    echo json_encode(['success' => false, 'message' => 'Unauthorized']);
    exit();
}

try {
    $query = "SELECT SettingKey, SettingValue, Description FROM tblsettings_loyalty ORDER BY ID";
    $result = mysqli_query($con, $query);
    
    if (!$result) {
        echo json_encode(['success' => false, 'message' => 'Database error']);
        exit();
    }
    
    $settings = [];
    while ($row = mysqli_fetch_assoc($result)) {
        $settings[$row['SettingKey']] = [
            'value' => $row['SettingValue'],
            'description' => $row['Description']
        ];
    }
    
    echo json_encode([
        'success' => true,
        'settings' => $settings
    ]);
    
} catch (Exception $e) {
    echo json_encode([
        'success' => false,
        'message' => 'Error fetching settings: ' . $e->getMessage()
    ]);
}
?>
