"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.resolveCodeLocation = void 0;
exports.validateAgentExists = validateAgentExists;
exports.getRuntimePackager = getRuntimePackager;
exports.getCodeZipPackager = getCodeZipPackager;
exports.getContainerPackager = getContainerPackager;
exports.packRuntime = packRuntime;
exports.packCodeZipSync = packCodeZipSync;
const schema_1 = require("../../schema");
const types_1 = require("../errors/types");
const container_1 = require("./container");
const helpers_1 = require("./helpers");
const node_1 = require("./node");
const python_1 = require("./python");
/**
 * Validate that an agent exists in the config
 * @param project AgentCore project configuration
 * @param agentName Name of agent to validate
 * @throws PackagingError if agent not found
 */
function validateAgentExists(project, agentName) {
    const agent = project.runtimes.find((a) => a.name === agentName);
    if (!agent) {
        const available = project.runtimes.map((a) => a.name).join(', ');
        throw new types_1.PackagingError(`Agent '${agentName}' not found. Available agents: ${available}`);
    }
}
/**
 * Get the async runtime packager for CLI usage based on runtime version.
 * Supports both Python and Node/TypeScript runtimes.
 */
function getRuntimePackager(runtimeVersion) {
    if ((0, helpers_1.isPythonRuntime)(runtimeVersion)) {
        return new python_1.PythonCodeZipPackager();
    }
    if ((0, helpers_1.isNodeRuntime)(runtimeVersion)) {
        return new node_1.NodeCodeZipPackager();
    }
    throw new types_1.PackagingError(`Unsupported runtime version: ${runtimeVersion}`);
}
/**
 * Get the sync CodeZip packager for CDK bundling based on runtime version.
 * Supports both Python and Node/TypeScript runtimes.
 */
function getCodeZipPackager(runtimeVersion) {
    if ((0, helpers_1.isPythonRuntime)(runtimeVersion)) {
        return new python_1.PythonCodeZipPackagerSync();
    }
    if ((0, helpers_1.isNodeRuntime)(runtimeVersion)) {
        return new node_1.NodeCodeZipPackagerSync();
    }
    throw new types_1.PackagingError(`Unsupported runtime version: ${runtimeVersion}`);
}
/**
 * Get the async runtime packager for Container agents.
 */
function getContainerPackager() {
    return new container_1.ContainerPackager();
}
/**
 * Package a runtime asynchronously.
 * This is the primary API for CLI usage.
 * Automatically selects the appropriate packager based on build type and runtime version.
 */
async function packRuntime(spec, options) {
    const packager = spec.build === 'Container' ? getContainerPackager() : getRuntimePackager(spec.runtimeVersion);
    return packager.pack(spec, options);
}
/**
 * Package a code bundle synchronously.
 * This is the primary API for CDK bundling.
 * Works with AgentEnvSpec or any object with name, codeLocation, and entrypoint.
 * Defaults to Python if no runtimeVersion is specified.
 */
function packCodeZipSync(config, options) {
    const runtimeVersion = config.runtimeVersion ?? schema_1.DEFAULT_PYTHON_VERSION;
    const packager = getCodeZipPackager(runtimeVersion);
    return packager.packCodeZip(config, options);
}
var helpers_2 = require("./helpers");
Object.defineProperty(exports, "resolveCodeLocation", { enumerable: true, get: function () { return helpers_2.resolveCodeLocation; } });
//# sourceMappingURL=index.js.map