<?php
header('Access-Control-Allow-Origin: *');
header('Content-Type: application/json');
require_once '../../../core/bootstrap.php';
require_once '../middleware/validate_token.php';

$fantasyLeagueModel = new FantasyLeague();

try {
    $leagues = $fantasyLeagueModel->getLeaguesForUser($authenticated_user_data->id);
    http_response_code(200);
    echo json_encode($leagues);
} catch (Exception $e) {
    http_response_code(500);
    echo json_encode(['message' => 'An error occurred while fetching your leagues.']);
}

?>