import { PHXClientMutationV3 } from '../GRPC/PHXGrpcClientV3';
import { chunkArray } from './utils';
export default async function PHXChunkUpdateMany({ chunk = 5, ids, idsKey = 'ids', key, onProgress, query, variables, }) {
    var _a;
    let totalAffectedRows = 0;
    const chunkIds = chunkArray(ids, chunk);
    const totalChunks = chunkIds.length;
    for (let i = 0; i < totalChunks; i++) {
        const chunkItem = chunkIds[i];
        const res = await PHXClientMutationV3({
            query,
            variables: {
                [idsKey]: chunkItem,
                ...variables,
            },
        });
        if (key)
            totalAffectedRows += ((_a = res.data) === null || _a === void 0 ? void 0 : _a[key].affected_rows) || 0;
        const current = (i + 1) * chunkItem.length;
        const total = ids.length;
        const percentage = Math.round((current / total) * 100);
        if (onProgress) {
            onProgress({
                current,
                total,
                percentage,
                currentChunk: i + 1,
                totalChunks,
            });
        }
    }
    return totalAffectedRows;
}
//# sourceMappingURL=index.js.map