"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LogUC = void 0;
exports.makeLogUC = makeLogUC;
const core_1 = require("@vived/core");
const AppDispatcher_1 = require("../Entities/AppDispatcher");
class LogUC extends core_1.AppObjectUC {
    constructor() {
        super(...arguments);
        this.requestType = "SUBMIT_LOG";
    }
}
exports.LogUC = LogUC;
LogUC.type = "LogUC";
LogUC.get = (appObjects) => (0, core_1.getSingletonComponent)(LogUC.type, appObjects);
function makeLogUC(appObject) {
    return new LogUCImp(appObject);
}
class LogUCImp extends LogUC {
    doDispatch(sender, message, severity) {
        if (!this.appDispatcher)
            return;
        const payload = {
            sender,
            severity,
            message,
        };
        this.appDispatcher.formRequestAndDispatch(this.requestType, this.requestVersion, payload);
    }
    constructor(appObject) {
        super(appObject, LogUC.type);
        this.requestVersion = 1;
        this.dispatchLog = (sender, message) => {
            this.doDispatch(sender, message, "LOG");
        };
        this.dispatchWarn = (sender, message) => {
            this.doDispatch(sender, message, "WARNING");
        };
        this.dispatchError = (sender, message) => {
            this.doDispatch(sender, message, "ERROR");
        };
        this.dispatchFatal = (sender, message) => {
            this.doDispatch(sender, message, "FATAL");
        };
        this.appDispatcher = appObject.getComponent(AppDispatcher_1.AppDispatcher.type);
        if (!this.appDispatcher) {
            this.warn(`${LogUC.type} has been added to an App Object that does not have a AppDispatcher. Add a dispatcher first`);
        }
    }
}
//# sourceMappingURL=LogUC.js.map