/**
 * Base helper for prompt modules that load a markdown file from disk.
 *
 * DomainSOPModule and RiskPolicyModule share identical structure:
 *   1. Check a config key to decide shouldInclude
 *   2. Build a path from projectRoot + subDir + configValue
 *   3. Read the file, format with a heading, or return a fallback
 *
 * This helper captures that pattern so each concrete module only
 * supplies metadata (name, priority, heading label, config key, etc.).
 *
 * @module services/ai/prompt-modules/markdown-file-module
 */
import * as fs from 'fs';
import * as path from 'path';
/**
 * Build a PromptModule from a MarkdownFileModuleDescriptor.
 *
 * @param descriptor - Module metadata and behavior hooks
 * @returns A fully implemented PromptModule
 */
export function buildMarkdownFileModule(descriptor) {
    return {
        name: descriptor.name,
        priority: descriptor.priority,
        maxTokens: descriptor.maxTokens,
        compactable: descriptor.compactable,
        shouldInclude(config) {
            return !!descriptor.getConfigValue(config);
        },
        async build(config) {
            const value = descriptor.getConfigValue(config);
            const filePath = path.join(config.projectRoot, 'config', descriptor.configSubDir, `${value}${descriptor.fileExtension}`);
            try {
                const content = fs.readFileSync(filePath, 'utf-8').trim();
                return `## ${descriptor.headingLabel}: ${value}\n\n${content}`;
            }
            catch {
                return `## ${descriptor.headingLabel}: ${value}\n\n_${descriptor.missingFileHint} ${filePath}. Create it to define ${descriptor.headingLabel.toLowerCase()}-specific procedures._`;
            }
        },
    };
}
//# sourceMappingURL=markdown-file-module.js.map