// Generated file. To retain edits, remove this comment.
import { InterfaceTypes, runPipeline } from 'itk-wasm';
import { getPipelinesBaseUrl } from './pipelines-base-url.js';
import { getPipelineWorkerUrl } from './pipeline-worker-url.js';
import { getDefaultWebWorker } from './default-web-worker.js';
/**
 * Write a DICOM RT Struct Structured Set for the given ROI contours and DICOM metadata
 *
 * @param {File | TextFile} inputCxt - Input Plastimatch CXT structure set file
 * @param {string} outputDicom - Output DICOM RT Struct Structure Set file
 * @param {WriteRtStructOptions} options - options object
 *
 * @returns {Promise<WriteRtStructResult>} - result object
 */
async function writeRtStruct(inputCxt, outputDicom, options = {}) {
    const desiredOutputs = [
        { type: InterfaceTypes.BinaryFile, data: { path: outputDicom, data: new Uint8Array() } },
    ];
    let inputCxtFile = inputCxt;
    if (inputCxt instanceof File) {
        const inputCxtBuffer = await inputCxt.arrayBuffer();
        inputCxtFile = { path: inputCxt.name, data: new TextDecoder().decode(inputCxtBuffer) };
    }
    const inputs = [
        { type: InterfaceTypes.TextFile, data: inputCxtFile },
    ];
    const args = [];
    // Inputs
    const inputCxtName = inputCxtFile.path;
    args.push(inputCxtName);
    // Outputs
    const outputDicomName = outputDicom;
    args.push(outputDicomName);
    // Options
    args.push('--memory-io');
    if (options.dicomMetadata) {
        const inputCountString = inputs.length.toString();
        inputs.push({ type: InterfaceTypes.JsonCompatible, data: options.dicomMetadata });
        args.push('--dicom-metadata', inputCountString);
    }
    const pipelinePath = 'write-rt-struct';
    let workerToUse = options?.webWorker;
    if (workerToUse === undefined) {
        workerToUse = await getDefaultWebWorker();
    }
    const { webWorker: usedWebWorker, returnValue, stderr, outputs } = await runPipeline(pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl(), webWorker: workerToUse, noCopy: options?.noCopy });
    if (returnValue !== 0 && stderr !== "") {
        throw new Error(stderr);
    }
    const result = {
        webWorker: usedWebWorker,
        outputDicom: outputs[0]?.data,
    };
    return result;
}
export default writeRtStruct;
//# sourceMappingURL=write-rt-struct.js.map