"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.assistantStreamingMutationReduceChunksResolver = void 0;
const graphql_transformer_core_1 = require("@aws-amplify/graphql-transformer-core");
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const graphql_transformer_common_1 = require("graphql-transformer-common");
const assistantStreamingMutationReduceChunksResolver = (config) => {
    let resolver = fs_1.default.readFileSync(path_1.default.join(__dirname, 'assistant-streaming-mutation-reduce-chunks-resolver-fn.template.js'), 'utf8');
    const fieldName = (0, graphql_transformer_common_1.toUpper)(config.field.name.value);
    const substitutions = {
        CONVERSATION_MESSAGE_TYPE_NAME: `ConversationMessage${fieldName}`,
    };
    Object.entries(substitutions).forEach(([key, value]) => {
        const replaced = resolver.replace(new RegExp(`\\[\\[${key}\\]\\]`, 'g'), value);
        resolver = replaced;
    });
    const templateName = `Mutation.${config.field.name.value}.assistant-response-stream.js`;
    return graphql_transformer_core_1.MappingTemplate.s3MappingFunctionCodeFromString(resolver, templateName);
};
exports.assistantStreamingMutationReduceChunksResolver = assistantStreamingMutationReduceChunksResolver;
//# sourceMappingURL=assistant-streaming-mutation-reduce-chunks-resolver.js.map