<?php
// api/roles/index.php

require_once '../../config/cors.php';
require_once '../../config/db.php';
require_once '../../helpers/response.php';
require_once '../../helpers/auth.php';

$method = getRequestMethod();

if ($method === 'OPTIONS') {
    http_response_code(200);
    exit;
}

requireAdmin();

if ($method === 'GET') {
    try {
        $stmt = $pdo->query("SELECT id, name FROM roles ORDER BY id");
        $roles = $stmt->fetchAll();
        
        sendSuccess($roles);
        
    } catch (PDOException $e) {
        sendError('Database error: ' . $e->getMessage(), 500);
    }
} else {
    sendError('Method not allowed', 405);
}
?>  