import{List as e}from"../utils/List.mjs";const{hasOwnProperty:n}=Object.prototype;function t(e){return"number"==typeof e&&isFinite(e)&&Math.floor(e)===e&&e>=0}function o(e){return Boolean(e)&&t(e.offset)&&t(e.line)&&t(e.column)}function r(t,r){return function(i,s){if(!i||i.constructor!==Object)return s(i,"Type of node should be an Object");for(let c in i){let l=!0;if(!1!==n.call(i,c)){if("type"===c)i.type!==t&&s(i,"Wrong node type `"+i.type+"`, expected `"+t+"`");else if("loc"===c){if(null===i.loc)continue;if(i.loc&&i.loc.constructor===Object)if("string"!=typeof i.loc.source)c+=".source";else if(o(i.loc.start)){if(o(i.loc.end))continue;c+=".end"}else c+=".start";l=!1}else if(r.hasOwnProperty(c)){l=!1;for(let n=0;!l&&n<r[c].length;n++){const t=r[c][n];switch(t){case String:l="string"==typeof i[c];break;case Boolean:l="boolean"==typeof i[c];break;case null:l=null===i[c];break;default:"string"==typeof t?l=i[c]&&i[c].type===t:Array.isArray(t)&&(l=i[c]instanceof e)}}}else s(i,"Unknown field `"+c+"` for "+t+" node type");l||s(i,"Bad value for `"+t+"."+c+"`")}}for(const e in r)n.call(r,e)&&!1===n.call(i,e)&&s(i,"Field `"+t+"."+e+"` is missed")}}function i(e,n){const t=[];for(let o=0;o<e.length;o++){const r=e[o];if(r===String||r===Boolean)t.push(r.name.toLowerCase());else if(null===r)t.push("null");else if("string"==typeof r)t.push(r);else{if(!Array.isArray(r))throw new Error("Wrong value `"+r+"` in `"+n+"` structure definition");t.push("List<"+(i(r,n)||"any")+">")}}return t.join(" | ")}function s(e,t){const o=t.structure,s={type:String,loc:!0},c={type:'"'+e+'"'};for(const t in o){if(!1===n.call(o,t))continue;const r=s[t]=Array.isArray(o[t])?o[t].slice():[o[t]];c[t]=i(r,e+"."+t)}return{docs:c,check:r(e,s)}}function c(e){const t={};if(e.node)for(const o in e.node)if(n.call(e.node,o)){const n=e.node[o];if(!n.structure)throw new Error("Missed `structure` field in `"+o+"` node type definition");t[o]=s(o,n)}return t}export{c as getStructureFromConfig};