"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkEntityFeature = checkEntityFeature;
const get_with_default_1 = require("../../objects/get-with-default");
const getPolicyResponseCode_1 = require("./getPolicyResponseCode");
// NOTE: Entity Feature Flagging is handled in checkPermission directly
// as it needs to interact with the feature flagging, and depending on
// the outcome, possibly omit some of the checks
function checkEntityFeature(policy, _entitycontext, entity) {
    const checks = [];
    // Only check things if the policy can be configured by the entity
    // This prevents arbitrary checks from being overriden by the entity
    if (entity && policy.entityConfigurable) {
        const result = "feature-enabled";
        // create the check, default to enabled
        const check = {
            name: `entity feature enabled`,
            value: `entity feature ${policy.permission} check`,
            code: (0, getPolicyResponseCode_1.getPolicyResponseCode)(result),
            response: result,
        };
        // Check if the feature is enabled for the entity defaulting to true
        const isFeatureEnabled = (0, get_with_default_1.getWithDefault)(entity, `features.${policy.permission}`, true);
        if (!isFeatureEnabled) {
            check.response = "feature-disabled";
            check.code = (0, getPolicyResponseCode_1.getPolicyResponseCode)("feature-disabled");
        }
        checks.push(check);
    }
    return checks;
}
//# sourceMappingURL=checkEntityFeature.js.map