"use strict";var e=this&&this.__awaiter||function(e,t,r,i){return new(r||(r=Promise))((function(n,o){function s(e){try{u(i.next(e))}catch(e){o(e)}}function a(e){try{u(i.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,a)}u((i=i.apply(e,t||[])).next())}))},t=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.BaseParameterizationParser=void 0;const r=require("./types"),i=require("./index"),n=t(require("../../log")),o=require("../../util/FsUtil"),s=require("../../common/message");exports.BaseParameterizationParser=class{constructor(e){this.parameterizationCache=new Map,this.supportValues=Object.values(r.SUPPORT_PARAMETER_KEY),this.parameterFile=e}isParameter(t){return e(this,void 0,void 0,(function*(){if(!t)return!1;if("object"!=typeof t)return`${t}`.includes(r.PREFIX_PARAMETER);try{return JSON.stringify(t).includes(r.PREFIX_PARAMETER)}catch(e){return n.default.warn("",`the param '${t}' may be a invalid json object, detail: ${e}`),!1}}))}canModify(t,r){return e(this,void 0,void 0,(function*(){const e=yield o.FsUtil.readJSON5(t);if(!e)throw new Error(s.Messages.Common.PkgNotFound);for(const t of this.supportValues){const n=(0,i.getObjectValueByKey)(t,e);if(!(yield this.recursiveCheck(t,n,r)))return!1}return!0}))}parseParameter(t,r,n){return e(this,void 0,void 0,(function*(){if("object"==typeof r){const e=Object.keys(r);for(const t of e){const e=(0,i.getObjectValueByKey)(t,r);yield this.parseParameter(t,e,r)}}else"object"==typeof n&&(yield this.isParameter(r))&&(n[t]=yield this.parameterFile.findVersion(r))}))}recursiveCheck(t,r,n){return e(this,void 0,void 0,(function*(){if("object"==typeof r){const e=Object.keys(r);for(const t of e){if(t!==n)continue;const e=(0,i.getObjectValueByKey)(t,r);if(!(yield this.recursiveCheck(t,e,n)))return!1}return!0}return!(t===n&&(yield this.isParameter(r)))}))}};