import*as u from"util";import{Lang as r,NamingVariableConventions as l,VariableType as c}from"./constants.js";import o from"./string-utility.js";const S={[r.NODEJS]:l.CAMEL_CASE,[r.JAVASCRIPT]:l.CAMEL_CASE,[r.PYTHON]:l.UNDER_SCORES,[r.JAVA8]:l.CAMEL_CASE,[r.JAVA]:l.CAMEL_CASE,[r.CSHARP]:l.PASCAL_CASE,[r.CSHARPNEWTONSOFT]:l.PASCAL_CASE,[r.CURL]:l.CAMEL_CASE,[r.GO]:l.CAMEL_CASE,[r.PHP]:l.CAMEL_CASE,[r.RUBY]:l.UNDER_SCORES,[r.R]:l.UNDER_SCORES},p={default:{joinSymbol:"",variableWrapperFn:a=>a,stringLiteral:a=>a,variableDeclaration:a=>a,urlFieldName:"url"},[r.CSHARP]:{joinSymbol:" + ",stringLiteral:a=>`"${a}"`,variableDeclaration:a=>`var ${a} = %s;`,urlFieldName:"fullUrl"},[r.CSHARPNEWTONSOFT]:{joinSymbol:" + ",stringLiteral:a=>`"${a}"`,variableDeclaration:a=>`var ${a} = %s;`,urlFieldName:"fullUrl"},[r.GO]:{joinSymbol:" + ",stringLiteral:a=>`"${a}"`,variableDeclaration:a=>`${a} := %s;`},[r.JAVA]:{joinSymbol:" + ",stringLiteral:a=>`"${a}"`,variableDeclaration:a=>`var ${a} = %s;`,urlFieldName:"pathname"},[r.JAVA8]:{joinSymbol:" + ",stringLiteral:a=>`"${a}"`,variableDeclaration:a=>`String ${a} = %s;`,urlFieldName:"fullUrl"},[r.JAVASCRIPT]:{variableWrapperFn:a=>"${"+a+"}",variableDeclaration:(a,i)=>`const ${a} = ${i?.hasVariableInterpolation?"`%s`":"'%s'"};`},[r.NODEJS]:{variableWrapperFn:a=>"${"+a+"}",variableDeclaration:(a,i)=>`const ${a} = ${i?.hasVariableInterpolation?"`%s`":"'%s'"};`},[r.PHP]:{joinSymbol:" . ",stringLiteral:a=>`"${a}"`,variableDeclaration:a=>`const ${a} = %s;`},[r.PYTHON]:{stringLiteral:a=>`"${a}"`,joinSymbol:" + ",variableDeclaration:a=>`${a} = %s`},[r.RUBY]:{joinSymbol:" + ",stringLiteral:a=>`'${a}'`,variableDeclaration:a=>`${a} = %s`},[r.CURL]:{variableWrapperFn:(a,i)=>i!=null&&i!==""?i:`{${a}}`,urlFieldName:"fullUrl",rawName:!0},[r.R]:{joinSymbol:" %&% ",variableDeclaration:a=>`${a} = %s`,urlFieldName:"fullUrl",stringLiteral:a=>`"${a}"`,variableWrapperFn:a=>`${a}`}},b=["response","request","requests","data","url","payload","main","accessToken","resp","Program","client","postData","App","httpClient","params","pathname","host","body","fetch","query"];class A{code;indentation;variablesPrefix;lineJoin;capitalize;lang;langOptions;constructor({indentation:i,lineJoin:t=`
`,variablesPrefix:e="",capitalize:n=!1,lang:s=r.CURL}){this.code=[],this.indentation=i,this.variablesPrefix=e,this.lineJoin=t||`
`,this.capitalize=n,this.lang=s,this.langOptions={...p.default,...p[s]}}buildLine(i,t){let e="",n=2;if(typeof i=="string")n=1,t=i,i=0;else if(i===null)return null;for(;i;)e+=this.indentation,i--;const s=Array.prototype.slice.call(arguments,n,arguments.length);return s.unshift(e+t),u.format.apply(this,s)}unshift(...i){return this.code.unshift(this.buildLine.apply(this,i)),this}push(...i){return this.code.push(this.buildLine.apply(this,i)),this}blank(){return this.code.push(null),this}join(){return this.code.join(this.lineJoin)}clean(){this.code.splice(1)}var(i,t=c.CUSTOM){if(t===c.PATH){let e=this.variablesPrefix+i;switch(b.includes(e)&&(e=`${e}_path`),S[this.lang]){case l.UNDER_SCORES:e=o.toSnakeCase(e);break;case l.PASCAL_CASE:e=o.toPascalCase(e);break;case l.CAMEL_CASE:default:e=o.toCamelCase(e);break}return e}return this.variablesPrefix?this.variablesPrefix+(this.capitalize?o.toPascalCase(i):i):i}}export{A as CodeBuilder};
