import { AppObjectUC, getSingletonComponent, } from "@vived/core";
import { BaseAppState } from "../../BaseApp/Entity/BaseAppState";
import { LabelDropRepo } from "../Entities/LabelDropRepo";
export class ValidateLabelDrop extends 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 getSingletonComponent(ValidateLabelDrop.type, appObjects);
    }
}
ValidateLabelDrop.type = "ValidateLabelDrop";
export function makeValidateLabelDrop(appObject) {
    return new ValidateLabelDropImp(appObject);
}
class ValidateLabelDropImp extends ValidateLabelDrop {
    get baseApp() {
        return this.getCachedSingleton(BaseAppState.type);
    }
    get labelDrop() {
        return this.getCachedSingleton(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