/**
 * Default Promise Transformer Plugin
 * Wraps the existing PromiseTransformer
 */
import * as t from '@babel/types';
import { PromiseTransformer } from '../../transformer/promise-transformer.js';
export class DefaultPromiseTransformerPlugin {
    name = 'atp-promise-transformer';
    version = '1.0.0';
    priority = 100;
    transformer;
    constructor(enableBatchParallel) {
        this.transformer = new PromiseTransformer(enableBatchParallel);
    }
    getVisitor(config) {
        return {
            CallExpression: (path) => {
                const node = path.node;
                if (this.isPromiseAllCall(node)) {
                    this.transformer.transformPromiseAll(path);
                }
                else if (this.isPromiseAllSettledCall(node)) {
                    this.transformer.transformPromiseAllSettled(path);
                }
            },
        };
    }
    getMetadata() {
        return {
            parallelCallCount: this.transformer.getTransformCount(),
        };
    }
    reset() {
        this.transformer.resetTransformCount();
    }
    isPromiseAllCall(node) {
        const callee = node.callee;
        return (t.isMemberExpression(callee) &&
            t.isIdentifier(callee.object, { name: 'Promise' }) &&
            t.isIdentifier(callee.property, { name: 'all' }));
    }
    isPromiseAllSettledCall(node) {
        const callee = node.callee;
        return (t.isMemberExpression(callee) &&
            t.isIdentifier(callee.object, { name: 'Promise' }) &&
            t.isIdentifier(callee.property, { name: 'allSettled' }));
    }
}
//# sourceMappingURL=promise-transformer-plugin.js.map