"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getFaceSheet = void 0;
const axios_1 = __importDefault(require("axios"));
const lodash_1 = require("lodash");
const DEFAULT_FACESHEET = 'https://res.cloudinary.com/da7x4rzl4/image/upload/v1707740015/Awell%20Extensions/WestFax/default_facesheet.pdf';
const getFaceSheet = async (customFaceSheetUrl) => {
    try {
        const pdfUrl = (0, lodash_1.isNil)(customFaceSheetUrl) || (0, lodash_1.isEmpty)(customFaceSheetUrl)
            ? DEFAULT_FACESHEET
            : customFaceSheetUrl;
        const headResponse = await axios_1.default.head(pdfUrl);
        // Check if the Content-Type header indicates a PDF file
        if (headResponse.headers['content-type'] === 'application/pdf') {
            // If it's a PDF, make a GET request to download the file
            const response = await axios_1.default.get(pdfUrl, { responseType: 'arraybuffer' });
            const faceSheetPdfBuffer = Buffer.from(response.data);
            return faceSheetPdfBuffer;
        }
        else {
            throw new Error('Face sheet URL does not point to a valid PDF file.');
        }
    }
    catch (error) {
        console.error('Error reading the face sheet template:', error);
        throw error;
    }
};
exports.getFaceSheet = getFaceSheet;
//# sourceMappingURL=getFaceSheet.js.map