import { mesh_to_metis_graph } from "./mesh_to_metis_graph.js";
import { metis_cluster_bs } from "./metis_cluster_bs.js";

/**
 * @deprecated Delegates to the deprecated `metis_cluster_bs`, which uses the
 * WASM-backed `Metis.INSTANCE`. Replace with the native equivalent:
 *
 *   import { metis_partition_kway } from "./native/metis_partition_kway.js";
 *   import { mesh_to_metis_graph } from "./mesh_to_metis_graph.js";
 *
 *   const csr = mesh_to_metis_graph(Array.from(mesh.getFaces()));
 *   const k = Math.ceil(face_count / patch_size);
 *   const partition = metis_partition_kway(face_count, k, csr.edge_addresses,
 *       csr.adjacency, csr.edge_weights, { seed: 0xCAFE });
 *
 * The native call is synchronous, so this becomes a non-async wrapper.
 *
 * @param {Uint32Array} result
 * @param {TopoMesh} mesh
 * @param {number} patch_size
 * @returns {number}
 */
export async function cluster_mesh_metis(result, mesh, patch_size) {

    const face_set = mesh.getFaces();
    const input_face_count = face_set.size;

    const face_array = Array.from(face_set);

    const metis_graph = mesh_to_metis_graph(face_array);

    const partition_count = await metis_cluster_bs(
        result,
        input_face_count,
        metis_graph.edge_addresses,
        metis_graph.adjacency,
        metis_graph.edge_weights,
        patch_size
    );

    return partition_count;
}

