import { BuildCommandToCompressWithZipModel, BuildCommandToConvertArchiveModel, BuildCommandToCreateRarModel, BuildCommandToDecompress7ZModel, BuildCommandToDecompressWithUnarchiverModel, getCommand, } from '../shared/index.js';
// check if corrupted
// zip -T filename.zip
// 7z t file.zip
export function buildCommandToConvertArchive(source) {
    const input = BuildCommandToConvertArchiveModel.parse(source);
    const decompressInput = {
        input: {
            file: {
                path: input.input.file.path,
            },
        },
        output: {
            directory: input.temporary.directory,
        },
    };
    const compressInput = {
        input: {
            directory: input.temporary.directory,
        },
        output: {
            file: input.output.file,
        },
    };
    return [
        ...buildCommandToDecompressWithUnarchiver(decompressInput),
        ...buildCommandToCompressWithZip(compressInput),
    ];
}
export function buildCommandToCompressWithZip(source) {
    const input = BuildCommandToCompressWithZipModel.parse(source);
    const cmd = getCommand(`zip`);
    cmd.list.push('-r', input.output.file.path, input.input.directory.path);
    return [cmd];
}
export function buildCommandToDecompressWith7z(source) {
    const input = BuildCommandToDecompress7ZModel.parse(source);
    const cmd = getCommand(`7z`);
    cmd.list.push(`x`, `"${input.input.directory?.path ?? input.input.file?.path}"`, `-o`, `"${input.output.file.path}"`);
    return [cmd];
}
export function buildCommandToDecompressWithUnarchiver(source) {
    const input = BuildCommandToDecompressWithUnarchiverModel.parse(source);
    const cmd = getCommand(`unar`);
    cmd.list.push(`${input.input.file.path}`, `-o`, `${input.output.directory.path}`);
    cmd.list.push('--quiet');
    if (input.overwrite) {
        cmd.list.push(`-f`);
    }
    if (input.password) {
        cmd.list.push(`-p`, input.password);
    }
    return [cmd];
}
// https://github.com/ashang/unar/blob/master/README.md
export function buildCommandToCreateRar(source) {
    const input = BuildCommandToCreateRarModel.parse(source);
    // doesn't work on mac.
    const cmd = getCommand(`rar`);
    cmd.list.push(`a`, `"${input.output.file.path}"`, `"${input.input.directory.path}"`);
    return [cmd];
}
// https://superuser.com/questions/190053/universal-command-line-unarchiving-tool-on-a-mac
// atool
// .tar.gz, .tgz, .tar.bz, .tbz, .tar.bz2, .tbz2, .tar.Z, .tZ, .tar.lzo, .tzo, .tar.lz, .tlz, .tar.xz, .txz, .tar.7z, .t7z, .tar, .zip, .jar, .war, .rar, .lha, .lzh, .7z, .alz, .ace, .a, .arj, .arc, .rpm, .deb, .cab, .gz, .bz, .bz2, .gz, .bz, .bz2, .Z, .lzma, .lzo, .lz, .xz, .rz, .lrz, .7z, .cpio
//# sourceMappingURL=archive.js.map