<?php
declare(strict_types=1);
require_once __DIR__ . '/../lib.php';

hw_require_method(['GET']);

try {
    $pdo = hw_db();
    
    // Get all active membership plans
    $stmt = $pdo->query("SELECT * FROM membership_plans WHERE active = 1 ORDER BY price ASC");
    $plans = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
    // Parse JSON features for each plan
    foreach ($plans as &$plan) {
        $plan['features'] = json_decode($plan['features'] ?? '[]', true);
        $plan['price'] = (float)$plan['price'];
    }
    
    hw_json([
        'success' => true,
        'plans' => $plans
    ]);
} catch (Throwable $e) {
    hw_json(['success' => false, 'message' => 'Server error', 'error' => $e->getMessage()], 500);
}