

import { ClaimFormat } from "../../vc/models/ClaimFormat.mjs";
import "../../vc/index.mjs";
import { MdocRecord } from "../../mdoc/repository/MdocRecord.mjs";
import "../../mdoc/index.mjs";
import "../../sd-jwt-vc/index.mjs";

//#region src/modules/dif-presentation-exchange/utils/presentationsToCreate.ts
function getPresentationsToCreate(credentialsForInputDescriptor) {
	const presentationsToCreate = [];
	for (const [inputDescriptorId, credentials] of Object.entries(credentialsForInputDescriptor)) for (const credential of credentials) if (credential.claimFormat === ClaimFormat.SdJwtDc) presentationsToCreate.push({
		claimFormat: ClaimFormat.SdJwtDc,
		subjectIds: [],
		verifiableCredentials: [{
			inputDescriptorId,
			credential: credential.credentialRecord,
			additionalPayload: credential.additionalPayload
		}]
	});
	else if (credential.credentialRecord instanceof MdocRecord) presentationsToCreate.push({
		claimFormat: ClaimFormat.MsoMdoc,
		verifiableCredentials: [{
			inputDescriptorId,
			credential: credential.credentialRecord
		}],
		subjectIds: []
	});
	else {
		const subjectId = credential.credentialRecord.credential.credentialSubjectIds[0];
		const expectedClaimFormat = credential.credentialRecord.credential.claimFormat === ClaimFormat.LdpVc ? ClaimFormat.LdpVp : ClaimFormat.JwtVp;
		const matchingClaimFormatAndSubject = presentationsToCreate.find((p) => p.claimFormat === expectedClaimFormat && Boolean(p.subjectIds?.includes(subjectId)));
		if (matchingClaimFormatAndSubject) matchingClaimFormatAndSubject.verifiableCredentials.push({
			inputDescriptorId,
			credential: credential.credentialRecord
		});
		else presentationsToCreate.push({
			claimFormat: expectedClaimFormat,
			subjectIds: [subjectId],
			verifiableCredentials: [{
				credential: credential.credentialRecord,
				inputDescriptorId
			}]
		});
	}
	return presentationsToCreate;
}

//#endregion
export { getPresentationsToCreate };
//# sourceMappingURL=presentationsToCreate.mjs.map