import { BadRequestException } from '@nestjs/common'; /** * A wagon carries ONE 40ft OR TWO 20ft empties — never a mix, never three. * Throws on the first wagon that breaks the rule. */ export function assertWagonLoad(sizesByWagon: Map): void { for (const [wagon, sizes] of sizesByWagon) { const has40 = sizes.some((size) => size === '40'); if ((has40 && sizes.length > 1) || sizes.length > 2) { throw new BadRequestException( `Wagon ${wagon} takes one 40ft or two 20ft containers — got ${sizes.join('ft + ')}ft`, ); } } }