<?php
require_once __DIR__ . '/../config/database.php';

header('Content-Type: application/json');

$method = $_SERVER['REQUEST_METHOD'];

if ($method === 'GET') {
    $res = supabase_rest('GET', 'game_plugins?select=game_key,name,name_ar,description_ar,icon_url,banner_url,is_enabled,is_beta,min_players,max_players,supports_ranked,supports_bot,default_time_controls,config,sort_order&order=sort_order.asc');

    $games = $res['data'] ?? [];
    echo json_encode(['games' => $games]);
} else {
    http_response_code(405);
    echo json_encode(['error' => 'method not allowed']);
}
