function assertValidBranches(branches, discriminator) {
    if (Object.keys(branches).length === 0) {
        throw new Error("OneOf schema requires at least one branch");
    }
    for (const [branchName, branch] of Object.entries(branches)) {
        if (Object.prototype.hasOwnProperty.call(branch.shape, discriminator)) {
            throw new Error(`OneOf branch "${branchName}" must not declare discriminator field "${discriminator}".`);
        }
    }
}
export function OneOf(config) {
    assertValidBranches(config.branches, config.discriminator);
    return {
        kind: "oneOf",
        discriminator: config.discriminator,
        branches: config.branches,
    };
}
