/** @internal NOTE: Internal APIs. Subject to change. Use of these APIs in production applications is not supported. */ /** */
import { BimIfcProductsAndMeshes } from './vertex-data-merge';
import { ProductMeshesGroupRenderInfo } from './ProductMeshesGroupRenderInfo';
import { BaseProductMeshesGroupRenderInfo } from './BaseProductMeshesGroupRenderInfo';

/**
 * Class to record render property statistics for a collection of merged IFC product meshes.
 */
export class MergedIfcProductMeshesRenderInfo extends BaseProductMeshesGroupRenderInfo {
    /**
     * Constructor.
     * @param parent - The parent render info object.
     */
    public constructor(public readonly parent: ProductMeshesGroupRenderInfo) {
        super(parent);
    }

    /**
     * Assign the render properties to the given IFC product and meshes.
     * @param ifcProductAndMeshes - The IFC product and meshes to assign the render properties to.
     */
    public assign(ifcProductAndMeshes: BimIfcProductsAndMeshes): void {
        for (const productMeshes of ifcProductAndMeshes.values()) {
            for (const productMesh of productMeshes) {
                productMesh._renderPropertyInfo = this;
                this._state.count++;
                // Using type coercion to convert boolean to number for performance optimization
                this._state.visibleCount += (0 as any) + productMesh.visible;
                this._state.outlinedCount += (0 as any) + productMesh.outline;
                this._state.ghostOutlineCount += (0 as any) + productMesh.ghostOutline;
                this._state.ignoreClipPlanesCount += (0 as any) + productMesh.ignoreClipPlanes;
            }
        }
    }

    /**
     * Detach the render properties from the given IFC product and meshes.
     * @param ifcProductAndMeshes - The IFC product and meshes to detach the render properties from.
     */
    public detach(ifcProductAndMeshes: BimIfcProductsAndMeshes): void {
        for (const productMeshes of ifcProductAndMeshes.values()) {
            for (const productMesh of productMeshes) {
                productMesh._renderPropertyInfo = undefined;
            }
        }
        this.clearState();
    }
}
