(async () => {
    // 1. Get Auth Data from the active client
    const apiClient = window.ApiClient;
    if (!apiClient) {
        console.error("ApiClient not found. Are you logged in?");
        return;
    }

    try {
        console.log("Fetching random item...");
        
        // 2. Fetch 1 random item
        // const result = await apiClient.getItems(apiClient.getCurrentUserId(), { SortBy: "Random", Limit: 1, Recursive: true, IncludeItemTypes: "Movie,Series" });
        const result = await apiClient.getItems(apiClient.getCurrentUserId(), {
            SortBy: "Random",
            Limit: 1,
            Recursive: true,
            IncludeItemTypes: "Movie,Series", // Optional: filter types
            Fields: "Overview,RemoteTrailers,Genres,CommunityRating,CriticRating,OfficialRating,PremiereDate,RunTimeTicks,ProductionYear,MediaSources" // Request ALL fields
        });

        if (result.Items.length > 0) {
            const item = result.Items[0];
            console.log("Random Item Found:", item.Name);
            console.dir(item); // Prints the full interactive object
        } else {
            console.warn("No items found.");
        }
    } catch (error) {
        console.error("Error fetching item:", error);
    }
})();
