import { AppObjectUC, getSingletonComponent, } from "@vived/core";
import { AppDispatcher } from "../Entities/AppDispatcher";
export class LogUC extends AppObjectUC {
    constructor() {
        super(...arguments);
        this.requestType = "SUBMIT_LOG";
    }
}
LogUC.type = "LogUC";
LogUC.get = (appObjects) => getSingletonComponent(LogUC.type, appObjects);
export 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.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