/* eslint-disable @typescript-eslint/no-extraneous-class */
/* eslint-disable @typescript-eslint/no-explicit-any */
import { PostmanBackupTransformer } from './PostmanBackupTransformer.js';
import { PostmanV2Transformer } from './PostmanV2Transformer.js';
import { PostmanV21Transformer } from './PostmanV21Transformer.js';
/**
 * Transforms Postman collections (v2 and v2.1) and Postman's data export
 * into an HTTP Project (or projects for data export).
 */
export class PostmanDataTransformer {
    static transform(init) {
        let data = init;
        if (typeof init === 'string') {
            data = JSON.parse(init);
        }
        const version = this.recognizeVersion(data);
        let instance;
        switch (version) {
            case 'backup':
                instance = new PostmanBackupTransformer(data);
                break;
            case 'collection-v2':
                instance = new PostmanV2Transformer(data);
                break;
            case 'collection-v2.1':
                instance = new PostmanV21Transformer(data);
                break;
            default:
                return Promise.reject(new Error('Unsupported Postman version.'));
        }
        return instance.transform();
    }
    static recognizeVersion(data) {
        if (data.version) {
            return 'backup';
        }
        if (data.info.schema) {
            switch (data.info.schema) {
                case 'https://schema.getpostman.com/json/collection/v2.0.0/collection.json':
                    return 'collection-v2';
                case 'https://schema.getpostman.com/json/collection/v2.1.0/collection.json':
                    return 'collection-v2.1';
                default:
                    return undefined;
            }
        }
        return undefined;
    }
}
//# sourceMappingURL=PostmanDataTransformer.js.map