<?php
/**
 * Get bonus and cashback info for users
 */

require_once 'config.php';

// Get bonus settings
$keys = ['wallet_bonus_enabled', 'wallet_bonus_percent', 'wallet_bonus_min_amount', 'cashback_enabled', 'cashback_percent'];

try {
    $placeholders = implode(',', array_fill(0, count($keys), '?'));
    $stmt = $pdo->prepare("SELECT key_name, value FROM settings WHERE key_name IN ($placeholders)");
    $stmt->execute($keys);
    
    $settings = [];
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
        $settings[$row['key_name']] = $row['value'];
    }
    
    echo json_encode([
        'ok' => true,
        'data' => [
            'wallet_bonus_enabled' => ($settings['wallet_bonus_enabled'] ?? '0') === '1',
            'wallet_bonus_percent' => (int)($settings['wallet_bonus_percent'] ?? 10),
            'wallet_bonus_min_amount' => (int)($settings['wallet_bonus_min_amount'] ?? 100000),
            'cashback_enabled' => ($settings['cashback_enabled'] ?? '0') === '1',
            'cashback_percent' => (int)($settings['cashback_percent'] ?? 5),
        ]
    ]);
} catch (PDOException $e) {
    echo json_encode([
        'ok' => true,
        'data' => [
            'wallet_bonus_enabled' => false,
            'wallet_bonus_percent' => 10,
            'wallet_bonus_min_amount' => 100000,
            'cashback_enabled' => false,
            'cashback_percent' => 5,
        ]
    ]);
}

