"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Transformer = void 0;
const __ΩPick = ['T', 'K', 'Pick', 'l+e#!e"!fRb!b"Pde""N#!w#y'];
function __assignType(fn, args) {
    fn.__type = args;
    return fn;
}
const lodash_1 = require("lodash");
const array_1 = require("./array");
class Transformer {
    static create(input) {
        return new Transformer(input);
    }
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    constructor(input) {
        this.input = input;
    }
    apply(fn, shouldApply = true) {
        this.executor = shouldApply ? fn : __assignType(input => input, ['input', '', 'P"2!"/"']);
        return (Transformer.Ω = [[() => fn, 'input', '', 'Pdi!P!F2"Ph#!Fh#!F`J/#qe!!!j']], new Transformer(this));
    }
    applyEach(fn, shouldApply = true) {
        return this.apply(__assignType(arr => arr.map(fn), ['arr', '', 'P"2!"/"']), shouldApply);
    }
    applyEachAsync(fn, shouldApply = true) {
        return this.apply(__assignType(arr => (0, array_1.asyncMap)(arr, fn), ['arr', '', 'P"2!"/"']), shouldApply);
    }
    narrow(...keys) {
        return this.apply(__assignType(input => {
            return input.map(__assignType(i => {
                return (0, lodash_1.pick)(i, ...keys);
            }, ['i', '', 'P"2!"/"']));
        }, ['input', '', 'P"2!"/"']));
    }
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    async execute() {
        if (!this.executor) {
            throw new Error('No executor defined');
        }
        const input = await this.get();
        return this.executor(input);
    }
    async get() {
        if (this.input instanceof Transformer) {
            return await this.input.execute();
        }
        else {
            return this.input;
        }
    }
}
exports.Transformer = Transformer;
Transformer.__type = ['I', 'input', '', 'executor', () => Transformer, 'create', () => Transformer, 'constructor', 'fn', 'shouldApply', () => Transformer, 'apply', () => Transformer, 'applyEach', () => Transformer, 'applyEachAsync', 'keys', () => __ΩPick, () => Transformer, 'narrow', 'execute', 'get', 'Transformer', 'b!Pe"!F2"P"F"F`J/#3$8;Pe"!F2"Pe#!7%0&sPPe#!FP"7\'J2";"0(PPe#!F2"P"F"F`J/#2)"2*P"7+0,PPe#!2""/#2)"2*P"7-0.PPe#!2""`/#2)"2*P"7/00P"@21Pe#!"\'fo2#7304P"F`05Pe"!F`065w7'];
//# sourceMappingURL=transformer.js.map