import { Archon } from "../Archon.js";
import { Session, SessionId } from "../types/user.js";

/**
 * Get the session object from the session ID.
 * @param sessionId The ID of the session to get.
 * @returns The session object.
 */
export default async function getSession(sessionId: SessionId | string): Promise<Session> {
    if (typeof sessionId !== "number") {
        sessionId = parseInt(sessionId) as SessionId;
    }
    const response = await Archon.request(`/users/session/${sessionId}`, "GET")
    if (response.status !== 200) {
        throw new Error(`Failed to retrieve session ${sessionId}.`);
    }

    return response.data;
}