import { getWithDefault } from "../../objects/get-with-default";
import { getPolicyResponseCode } from "./getPolicyResponseCode";
/**
 * Validate entityDelete policy - delegates to the
 * entity's canDelete property
 * @param policy
 * @param context
 * @param entity
 * @returns
 */
export function checkDelete(policy, context, entity) {
    const checks = [];
    if (Object.prototype.hasOwnProperty.call(policy, "entityDelete")) {
        let response = "granted";
        if (!entity) {
            // fail b/c no entity
            response = "entity-required";
        }
        else {
            if (policy.entityDelete && !entity.canDelete) {
                response = "no-delete-access";
            }
            else if (!policy.entityDelete && entity.canDelete) {
                response = "delete-access";
            }
        }
        const canDelete = getWithDefault(entity, "canDelete", false);
        // create the check
        const check = {
            name: "entity delete required",
            value: `entity.canDelete: ${canDelete.toString()}`,
            code: getPolicyResponseCode(response),
            response,
        };
        checks.push(check);
    }
    return checks;
}
//# sourceMappingURL=checkDelete.js.map