import{VariableType as u}from"./constants.js";function x({body:r,authorizationHeader:a}){return function(i,s,t){return r&&s==="body"&&typeof i.body=="string"?i.body:a&&s==="Authorization"&&typeof i.Authorization=="string"?i.Authorization:t}}function d(r,{level:a=0,indent:i="  ",firstLine:s=!0}={}){const t=i.repeat(a),e=r.replace(/(\r\n|\n|\r)/gm,`
${t}`);return s?t.concat(e):e}function c(r,a){const s=Object.keys(a).map(n=>({name:n,idx:r.indexOf(`{${n}}`)})).filter(({idx:n})=>n>-1).sort((n,o)=>n.idx-o.idx),t=[];let e=0;for(const{name:n,idx:o}of s)o>e&&t.push({type:"string",value:r.substring(e,o)}),t.push({type:"variable",name:n}),e=o+n.length+2;return e<r.length&&t.push({type:"string",value:r.substring(e)}),t}function g(r,a,i){const{joinSymbol:s,variableWrapperFn:t,stringLiteral:e,urlFieldName:n,rawName:o}=a.langOptions,{pathParameters:f={},serverVariables:b={}}=r,p={...f,...b};return c(i??r[n]??"",p).map(l=>{if(l.type==="variable"){const m=p[l.name],v=o?l.name:a.var(l.name,u.PATH);return t(v,m)}else return e(l.value)}).join(s)}function y(r,a,i){const s={...r.pathParameters,...r.serverVariables};Object.entries(s).forEach(([t,e])=>{if(t==="server")return;const n=e!=null&&e!==""?String(e):`YOUR_${t}_PARAMETER`,o=a.var(t,u.PATH),b=c(n,s).some(l=>l.type==="variable"),p=g(r,a,n);i!==void 0?a.push(i,a.langOptions.variableDeclaration(o,{hasVariableInterpolation:b}),p):a.push(a.langOptions.variableDeclaration(o,{hasVariableInterpolation:b}),p)})}export{d as addIndentation,g as buildUrlExpression,x as getPreserveTransformer,c as parseUrlIntoOperands,y as printUrlVariablesDeclarations};
