import { AppObjectUC, getSingletonComponent, } from "@vived/core";
import { ChannelModelRepo } from "../Entities/ChannelModelRepo";
export class ValidateChannelModel extends AppObjectUC {
    constructor() {
        super(...arguments);
        this.MUST_SELECT_MODEL = "You must select a model before saving.";
    }
    static get(appObjects) {
        return getSingletonComponent(ValidateChannelModel.type, appObjects);
    }
}
ValidateChannelModel.type = "ValidateChannelModel";
export function makeValidateChannelModel(appObject) {
    return new ValidateChannelModelImp(appObject);
}
class ValidateChannelModelImp extends ValidateChannelModel {
    get repo() {
        return this.getCachedSingleton(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