import { ReceiptBox, ReceiptPallet } from "../types/types.tsx";
import { ProductSchema, ResidualBoxSchema, ResidualPalletSchema } from "../../../../../client";

const findProductInObject = (
    object: ReceiptPallet | ReceiptBox | ResidualPalletSchema | ResidualBoxSchema,
    productsToSelect: ProductSchema[],
): ProductSchema | undefined => {
    for (let i = 0; i < productsToSelect.length; i++) {
        for (let j = 0; j < object.residualProducts.length; j++) {
            if (productsToSelect[i].id === object.residualProducts[j].product.id) {
                return productsToSelect[i];
            }
        }
    }
};

export default findProductInObject;
