"use strict";var t=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.LengthLimitRule=void 0;const e=require("./types"),i=t(require("../../../log")),n=require("../../../common/message");exports.LengthLimitRule=class{constructor(t,e,i){this.maxLength=t,this.minLength=e,this.errorCallback=i}validate(t,n,r){r=r||n,i.default.debug("",`start LengthLimitRule.validate attribute "${r}" in publishJson.`),!t[n]&&this.minLength>0&&this.errorCallback(r,{attrName:r,ruleType:e.ValidationRuleType.LengthLimit,errorMsg:this.getErrorMsg(r)});const h=t[n];h?((this.maxLength>0&&h.length>this.maxLength||this.minLength>0&&h.length<this.minLength)&&this.errorCallback(r,{attrName:r,ruleType:e.ValidationRuleType.LengthLimit,errorMsg:this.getErrorMsg(r)}),i.default.debug("",`LengthLimitRule.validate attribute "${r}" in publishJson succeed..`)):i.default.debug("",`attribute "${r}" is empty in publishJson.`)}getErrorMsg(t){if(this.maxLength>0&&this.minLength>=0)return`the length of attribute "${t}" in "oh-package.json5" must range [${this.minLength}, ${this.maxLength}]`;if(this.maxLength>0)return`the length of attribute "${t}" in "oh-package.json5" must range (0, ${this.maxLength}]`;if(this.minLength>0)return`the length of attribute "${t}" in "oh-package.json5" must range [${this.minLength}, Infinity)`;throw i.default.error("",`both "maxLen": ${this.maxLength} and \n      "minLen": ${this.minLength} in the LengthLimitRule are less than 0.`),new Error(n.Messages.Validator.UnknownError)}};