"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.resolveZipCompressionMethod = resolveZipCompressionMethod;
exports.resolveZipFlags = resolveZipFlags;
exports.buildZipEntryMetadata = buildZipEntryMetadata;
const text_1 = require("../utils/text.js");
const timestamps_1 = require("../utils/timestamps.js");
const zip_records_1 = require("../zip-spec/zip-records.js");
function resolveZipCompressionMethod(deflate) {
    return deflate ? zip_records_1.COMPRESSION_DEFLATE : zip_records_1.COMPRESSION_STORE;
}
function resolveZipFlags(useDataDescriptor) {
    return useDataDescriptor ? zip_records_1.FLAG_UTF8 | zip_records_1.FLAG_DATA_DESCRIPTOR : zip_records_1.FLAG_UTF8;
}
function buildZipEntryMetadata(input) {
    const nameBytes = (0, text_1.encodeUtf8)(input.name);
    const commentBytes = (0, text_1.encodeUtf8)(input.comment ?? "");
    const { dosTime, dosDate } = (0, timestamps_1.dateToZipDos)(input.modTime);
    const extraField = (0, timestamps_1.buildZipTimestampExtraField)(input.modTime, input.timestamps);
    return {
        nameBytes,
        commentBytes,
        dosTime,
        dosDate,
        extraField,
        compressionMethod: resolveZipCompressionMethod(input.deflate),
        flags: resolveZipFlags(input.useDataDescriptor)
    };
}
