import { Archon } from "../Archon.js";
import { ARID, Resource } from "../types/policy.js";

/**
 * Retrieve a resource by its ARID.
 * @param arid - The Archon Resource Identifier (ARID) of the resource to retrieve.
 * @returns A promise resolving to the resource, or null if not found.
 */
export default async function getResourceById(arid: ARID): Promise<Resource | null> {
    const response = await Archon.request(`/policy/resource/${arid}`, "GET");

    if (response.status === 404) {
        return null; // Resource not found
    }

    if (response.status !== 200) {
        throw new Error(`Failed to retrieve resource with ARID ${arid}: ${response.data}`);
    }

    return response.data;
}

