import { Archon } from "../Archon.js";
import { ResourceType, ResourceTypeName } from "../types/policy.js";

/**
 * Given a resource type name, return the resource type from the Archon policy service.
 * @param resourceTypeName the name of the resource type to retrieve, found in the archon.yaml file.
 * @returns The resource type from the Archon policy service.
 */
export default async function getResourceType(resourceTypeName: ResourceTypeName | string): Promise<ResourceType> {
    const response = await Archon.request(`/policy/type/${resourceTypeName}`, "GET");

    if (response.status !== 200) {
        throw new Error(`Failed to retrieve resource type ${resourceTypeName}.`);
    }

    return response.data;
}