import partTypeStrings from '@/constants/part-type-strings';

const recalPartTypes = [partTypeStrings.RECALIBRATION, partTypeStrings.ADAS_RECALIBRATION];

export function isRecalPart(part) {
    return recalPartTypes.some((type) => type === part.partType);
}

export function isRecalPartOrHasChildRecalPart(glassPart) {
    const isGlassPartRecalPart = isRecalPart(glassPart);

    if (!isGlassPartRecalPart && glassPart.childParts && glassPart.childParts.length > 0) {
        return glassPart.childParts.filter((cp) => isRecalPartOrHasChildRecalPart(cp));
    }

    return isGlassPartRecalPart;
}

export function getTopLevelGlassPartsWithRecal(glassParts) {
    if (!glassParts) {
        return null;
    }

    return glassParts.filter((gp) => isRecalPartOrHasChildRecalPart(gp));
}
