"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.JAVASCRIPT_CALL_API_FUNCTION = exports.PYTHON_CALL_API_FUNCTION = void 0;
exports.getCallApiFunctionName = getCallApiFunctionName;
exports.getDefaultProviderFilePath = getDefaultProviderFilePath;
exports.resolveProviderFilePath = resolveProviderFilePath;
exports.parseProviderFilePath = parseProviderFilePath;
/** Fixed entrypoint names — users only configure the file path in UI. */
exports.PYTHON_CALL_API_FUNCTION = 'call_api';
exports.JAVASCRIPT_CALL_API_FUNCTION = 'callApi';
function getCallApiFunctionName(language) {
    return language === 'py' ? exports.PYTHON_CALL_API_FUNCTION : exports.JAVASCRIPT_CALL_API_FUNCTION;
}
function getDefaultProviderFilePath(language) {
    return language === 'py' ? 'provider.py' : 'provider.js';
}
function validateProviderFileExtension(language, filePath) {
    const lower = filePath.toLowerCase();
    if (language === 'py') {
        if (!lower.endsWith('.py')) {
            throw new Error('Python provider file path must end with .py (e.g. provider.py or src/handler.py)');
        }
        return;
    }
    if (!lower.endsWith('.js') &&
        !lower.endsWith('.mjs') &&
        !lower.endsWith('.cjs') &&
        !/\.bundle\.(js|cjs|mjs)$/.test(lower)) {
        throw new Error('JavaScript provider file path must end with .js, .mjs, .cjs, or .bundle.js (e.g. provider.js or provider.bundle.js)');
    }
}
/**
 * Resolve provider file path from UI/API input. Colon suffix is not allowed (no file:function).
 */
function resolveProviderFilePath(language, input) {
    const raw = input?.trim() ?? '';
    if (raw.includes(':')) {
        throw new Error('Provide only the provider file path (e.g. provider.py or src/handler.js). ' +
            `Function name is fixed: ${exports.PYTHON_CALL_API_FUNCTION} for Python, ${exports.JAVASCRIPT_CALL_API_FUNCTION} for JavaScript.`);
    }
    const filePath = raw || getDefaultProviderFilePath(language);
    if (!filePath) {
        throw new Error('providerFilePath is required');
    }
    validateProviderFileExtension(language, filePath);
    return filePath.replace(/\\/g, '/');
}
function parseProviderFilePath(language, providerFilePath) {
    const fileName = resolveProviderFilePath(language, providerFilePath);
    return {
        fileName,
        functionName: getCallApiFunctionName(language),
    };
}
//# sourceMappingURL=parseProviderFilePath.js.map