import { encodeUtf8 } from "../utils/text.js";
import { buildZipTimestampExtraField, dateToZipDos } from "../utils/timestamps.js";
import { COMPRESSION_DEFLATE, COMPRESSION_STORE, FLAG_DATA_DESCRIPTOR, FLAG_UTF8 } from "../zip-spec/zip-records.js";
export function resolveZipCompressionMethod(deflate) {
    return deflate ? COMPRESSION_DEFLATE : COMPRESSION_STORE;
}
export function resolveZipFlags(useDataDescriptor) {
    return useDataDescriptor ? FLAG_UTF8 | FLAG_DATA_DESCRIPTOR : FLAG_UTF8;
}
export function buildZipEntryMetadata(input) {
    const nameBytes = encodeUtf8(input.name);
    const commentBytes = encodeUtf8(input.comment ?? "");
    const { dosTime, dosDate } = dateToZipDos(input.modTime);
    const extraField = buildZipTimestampExtraField(input.modTime, input.timestamps);
    return {
        nameBytes,
        commentBytes,
        dosTime,
        dosDate,
        extraField,
        compressionMethod: resolveZipCompressionMethod(input.deflate),
        flags: resolveZipFlags(input.useDataDescriptor)
    };
}
