import { client } from '$lib/minio';

/**
 * Check if caseNumber is used
 * @param {string} caseNumber
 * @returns {Promise<boolean}
 */
export default async function caseNumberOccupied(caseNumber) {
	const prefix = `${caseNumber}/config.json`;
	const promise = new Promise((resolve) => {
		let stream = client.listObjectsV2('tatort', prefix, false, '');
		stream.on('data', () => {
			stream.destroy();
			resolve(true);
		});
		stream.on('end', () => {
			resolve(false);
		});
	});

	return promise;
}
