"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.downloadRecordingController = void 0;
const logger_1 = __importDefault(require("../../../logger"));
/**
 * Controller to download/serve call recording audio from base64 data
 * This endpoint expects base64 audio data in the request body
 */
const downloadRecordingController = async (req, res) => {
    try {
        const { audioDataBase64, mimeType = 'audio/wav', filename } = req.body;
        if (!audioDataBase64) {
            res.status(400).json({
                success: false,
                error: 'Missing "audioDataBase64" parameter in request body.',
            });
            return;
        }
        // Decode base64 to Buffer
        const audioBuffer = Buffer.from(audioDataBase64, 'base64');
        // Set appropriate headers for audio file download/playback
        res.setHeader('Content-Type', mimeType || 'audio/wav');
        res.setHeader('Content-Length', audioBuffer.length);
        res.setHeader('Accept-Ranges', 'bytes');
        res.setHeader('Content-Disposition', filename ? `attachment; filename="${filename}"` : 'inline; filename="recording.wav"');
        // Send the audio buffer
        res.send(audioBuffer);
    }
    catch (error) {
        logger_1.default.error(`Error serving recording audio: ${error.message}`);
        res.status(500).json({
            success: false,
            error: error.message || 'Failed to serve recording audio',
        });
    }
};
exports.downloadRecordingController = downloadRecordingController;
//# sourceMappingURL=download-recording.js.map