import { getTextAttachmentType } from './attachment-upload.js';
const ARCHIVE_MIME_TYPES_BY_TYPE = {
    gz: new Set(['application/gzip', 'application/x-gzip']),
    tgz: new Set([
        'application/tar+gzip',
        'application/x-compressed-tar',
        'application/x-gtar',
        'application/x-tar+gzip',
        'application/x-tgz'
    ]),
    zip: new Set(['application/x-zip', 'application/x-zip-compressed', 'application/zip'])
};
function normalizeMimeType(mimeType) {
    return mimeType?.trim().toLowerCase() ?? '';
}
function normalizeFileName(fileName) {
    return fileName?.trim().toLowerCase() ?? '';
}
function hasAnyFileName(input) {
    return normalizeFileName(input.fileName).length > 0;
}
export function detectAttachmentArchiveType(input) {
    const fileName = normalizeFileName(input.fileName);
    if (fileName.endsWith('.tar.gz') || fileName.endsWith('.tgz')) {
        return 'tgz';
    }
    if (fileName.endsWith('.zip')) {
        return 'zip';
    }
    if (fileName.endsWith('.gzip') || fileName.endsWith('.gz')) {
        return 'gz';
    }
    const mimeType = normalizeMimeType(input.mimeType);
    if (!mimeType) {
        return null;
    }
    if (ARCHIVE_MIME_TYPES_BY_TYPE.zip.has(mimeType)) {
        return 'zip';
    }
    if (ARCHIVE_MIME_TYPES_BY_TYPE.tgz.has(mimeType)) {
        return 'tgz';
    }
    if (ARCHIVE_MIME_TYPES_BY_TYPE.gz.has(mimeType)) {
        return 'gz';
    }
    return null;
}
export function classifyAttachmentDelivery(input) {
    if (detectAttachmentArchiveType(input)) {
        return 'reference_only';
    }
    const mimeType = normalizeMimeType(input.mimeType);
    if (mimeType.startsWith('image/') || mimeType === 'application/pdf') {
        return 'inline_native';
    }
    if (getTextAttachmentType({
        fileName: input.fileName,
        mimeType
    }) !== null) {
        return 'inline_native';
    }
    return 'reference_only';
}
export function isSupportedAttachmentUploadType(input) {
    if (detectAttachmentArchiveType(input)) {
        return true;
    }
    if (!hasAnyFileName(input) && !normalizeMimeType(input.mimeType)) {
        return false;
    }
    return classifyAttachmentDelivery(input) === 'inline_native';
}
//# sourceMappingURL=attachment-delivery.js.map