"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ValidateLabelDrop = void 0;
exports.makeValidateLabelDrop = makeValidateLabelDrop;
const core_1 = require("@vived/core");
const BaseAppState_1 = require("../../BaseApp/Entity/BaseAppState");
const LabelDropRepo_1 = require("../Entities/LabelDropRepo");
class ValidateLabelDrop extends core_1.AppObjectUC {
    constructor() {
        super(...arguments);
        this.LABEL_DROP_ANSWER_REQUIRED = "At least one label drop answer item is required";
        this.LABEL_DROP_STILL_EDITING = "Cannot save while still editing a label drop answer";
    }
    static get(appObjects) {
        return (0, core_1.getSingletonComponent)(ValidateLabelDrop.type, appObjects);
    }
}
exports.ValidateLabelDrop = ValidateLabelDrop;
ValidateLabelDrop.type = "ValidateLabelDrop";
function makeValidateLabelDrop(appObject) {
    return new ValidateLabelDropImp(appObject);
}
class ValidateLabelDropImp extends ValidateLabelDrop {
    get baseApp() {
        return this.getCachedSingleton(BaseAppState_1.BaseAppState.type);
    }
    get labelDrop() {
        return this.getCachedSingleton(LabelDropRepo_1.LabelDropRepo.type);
    }
    constructor(appObject) {
        super(appObject, ValidateLabelDrop.type);
        this.validate = () => {
            if (!this.labelDrop) {
                this.error("Unable to find Label Drop Repo");
                return null;
            }
            if (this.labelDrop.getAll().length === 0) {
                return this.LABEL_DROP_ANSWER_REQUIRED;
            }
            if (this.labelDrop.editingID) {
                return this.LABEL_DROP_STILL_EDITING;
            }
            let itemValidation;
            this.labelDrop.getAll().forEach((item) => {
                if (item.labelEntity.customLabelValidationMessage) {
                    itemValidation = item.labelEntity.customLabelValidationMessage;
                }
                if (item.targetValidationMessage) {
                    itemValidation = item.targetValidationMessage;
                }
            });
            if (itemValidation) {
                return itemValidation;
            }
            return null;
        };
        this.appObjects.registerSingleton(this);
    }
}
//# sourceMappingURL=ValidateLabelDrop.js.map