import{GraphQLEnumType as y,GraphQLInputObjectType as g,GraphQLInterfaceType as $,GraphQLList as T,GraphQLNonNull as h,GraphQLObjectType as L,GraphQLScalarType as G,GraphQLUnionType as b}from"graphql";function Q(n){const s=n.toLowerCase();return["queries","mutations","subscriptions","directives"].includes(s)}function v(n,s,r){if(!Q(s))return;const e=s.toLowerCase();switch(e){case"queries":const t=r.getQueryField(n);return{name:t?.name,group:e,description:t?.description||void 0,response:t?c(t.type):void 0,args:a(t?.args)};case"mutations":const i=r.getMutationField(n);return{name:i?.name,group:e,description:i?.description||void 0,response:i?c(i.type):void 0,args:a(i?.args)};case"subscriptions":const o=r.getSubscriptionField(n);return{name:o?.name,group:e,description:o?.description||void 0,response:o?c(o.type):void 0,args:a(o?.args)};case"directives":const u=r.getDirective(n);return{name:u?.name,group:e,description:u?.description||void 0,locations:u?.locations.map(p=>p.toString()),isRepeatable:!!u?.isRepeatable,args:a(u?.args)};default:return}}function c(n,s=1,r=[]){const{type:e,list:t,notNull:i}=f(n),o=e.toString();if(r.includes(o)||r.length>=s)return o;if(e instanceof L)return{name:e.name,description:e.description||void 0,fields:d(e.getFields(),s,[...r,o])};if(e instanceof $)return{name:e.name,description:e.description||void 0,list:t,notNull:i,fields:d(e.getFields(),s,[...r,o])};if(e instanceof b)return{name:e.name,description:e.description||void 0,list:t,notNull:i,types:e.getTypes().map(u=>u.name)};if(e instanceof y){const u=e.getValues().map(p=>({name:p.name,description:p.description||void 0,value:p.value}));return{name:e.name,description:e.description||void 0,list:t,notNull:i,values:u}}else{if(e instanceof G)return o;if(e instanceof g)return{name:e.name,description:e.description||void 0,list:t,notNull:i,fields:d(e.getFields(),s,[...r,o])}}}function a(n,s=3){if(!n)return;const r={};return n.forEach(e=>{r[e.name]={type:c(e.type,s),description:e.description}}),r}function d(n,s,r){if(!n)return;const e={};return Object.entries(n).forEach(([t,i])=>{e[t]={type:c(i.type,s,r),description:i.description,defaultValue:i.defaultValue}}),e}function f(n){return n instanceof h?{type:f(n.ofType).type,notNull:!0}:n instanceof T?{type:f(n.ofType).type,list:!0}:{type:n}}function N(n){const{name:s,group:r,description:e,args:t,response:i,locations:o,isRepeatable:u}=n;let p=`# ${s}

**Type:** GraphQL ${r}

**Description:**
${e}

`;return p+=t?`## Arguments
${m(t)}

`:"",i&&(typeof i=="string"?p+=`## Response
**Type:** ${i}
`:(p+=`## Response
**Type:** ${i.name}
**Description:**
${i.description}

`,p+=i.fields?`### Fields
${m(i.fields)}
`:"")),p+=u?`## Repeatable
`:"",p+=o?`##Locations
${o.map(l=>`- ${l}`).join(`
`)}
`:"",p}function m(n,s=0){const r="  ".repeat(s);return n?Object.entries(n).map(([e,t])=>typeof t.type=="string"?`${r}- ${e} (${t.type}): ${t.description}`:`${r}- ${e} (${t.type.name}${t.type.notNull?", Not Null":""}): ${t.description}
${m(t.type.fields,s+1)}`).join(`
`):""}export{N as convertDocumentToMarkdown,v as getSearchDocument,Q as typeGroupNeedsSearchDocument};
