import { JsonValue } from "type-fest";
import { Archon } from "../Archon.js";

/**
 * Accesses the Archon configurator to retrieve the value of a configuration key.
 * @param key The key of the configuration value to retrieve.
 * @returns The value of the configuration key.
 */
export default async function getConfigValue(key: string): Promise<JsonValue> {
    const response = await Archon.request(`/config/item/${key}`, "GET");

    if (response.status !== 200) {
        throw new Error(`Failed to retrieve configuration value for key ${key}.`);
    }

    const data = response.data;
    return data.value;
}