"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ValidateChannelModel = void 0;
exports.makeValidateChannelModel = makeValidateChannelModel;
const core_1 = require("@vived/core");
const ChannelModelRepo_1 = require("../Entities/ChannelModelRepo");
class ValidateChannelModel extends core_1.AppObjectUC {
    constructor() {
        super(...arguments);
        this.MUST_SELECT_MODEL = "You must select a model before saving.";
    }
    static get(appObjects) {
        return (0, core_1.getSingletonComponent)(ValidateChannelModel.type, appObjects);
    }
}
exports.ValidateChannelModel = ValidateChannelModel;
ValidateChannelModel.type = "ValidateChannelModel";
function makeValidateChannelModel(appObject) {
    return new ValidateChannelModelImp(appObject);
}
class ValidateChannelModelImp extends ValidateChannelModel {
    get repo() {
        return this.getCachedSingleton(ChannelModelRepo_1.ChannelModelRepo.type);
    }
    constructor(appObject) {
        super(appObject, ValidateChannelModel.type);
        this.validate = () => {
            if (!this.repo)
                return null;
            if (!this.repo.activeModel) {
                return this.MUST_SELECT_MODEL;
            }
            const channelModel = this.repo.getForAppObject(this.repo.activeModel);
            if (!channelModel) {
                this.warn("Unable to get active channel model");
                return null;
            }
            let labelValidation = null;
            channelModel.modelObjects().forEach((obj) => {
                if (obj.label.customLabelValidationMessage) {
                    labelValidation = obj.label.customLabelValidationMessage;
                }
            });
            return labelValidation;
        };
        this.appObjects.registerSingleton(this);
    }
}
//# sourceMappingURL=ValidateChannelModel.js.map