"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.$ = void 0;
const EventEmitter_1 = require("../EventEmitter");
const global_1 = require("../global");
class $ extends EventEmitter_1.EventEmitter_ {
    constructor(system) {
        super();
        this.__ = [];
        this.__async = false;
        this.__ref_count = 0;
        this.__system = system;
        this.register();
    }
    getGlobalId() {
        return this.__global_id;
    }
    getInterface() {
        return this.__;
    }
    refSystem() {
        return this.__system;
    }
    register() {
        this.__ref_count++;
        if (this.__ref_count === 1) {
            this.__global_id = (0, global_1.setGlobalRef)(this.__system, this);
        }
        this.emit('register');
    }
    unregister() {
        this.__ref_count--;
        if (this.__ref_count === 0) {
            this.emit('unregister');
        }
    }
    destroy() {
        (0, global_1.deleteGlobalRef)(this.__system, this.__global_id);
        this.emit('destroy');
    }
    raw() {
        throw new Error("object doens't have raw form");
    }
}
exports.$ = $;
//# sourceMappingURL=$.js.map