"use strict";
var nextTransformerId = 0;
var markoModules = require("../modules");

class Transformer {
    constructor() {
        this.id = nextTransformerId++;
        this.name = null;
        this.tag = null;
        this.path = null;
        this.priority = null;
        this._func = null;
        this.properties = {};
    }

    getFunc() {
        if (!this.path) {
            throw new Error(
                "Transformer path not defined for tag transformer (tag=" +
                    this.tag +
                    ")"
            );
        }

        if (!this._func) {
            var transformer = markoModules.require(this.path);

            if (typeof transformer === "function") {
                if (transformer.prototype.process) {
                    var Clazz = transformer;
                    var instance = new Clazz();
                    instance.id = this.id;
                    this._func = instance.process.bind(instance);
                } else {
                    this._func = transformer;
                }
            } else {
                this._func = transformer.process || transformer.transform;
            }
        }
        return this._func;
    }
    toString() {
        return "[Taglib.Transformer: " + this.path + "]";
    }
}

module.exports = Transformer;
