// @bun
function W(B,g){let w=B.trim();if(w==="string")return{type:"string"};if(w==="number")return{type:"number"};if(w==="boolean")return{type:"boolean"};if(w==="null")return{type:"null"};if(w==="undefined")return{type:"null"};if(w==="any"||w==="unknown")return{};if(w==="never")return{not:{}};if(w==="void")return{type:"null"};if(w==="bigint")return{type:"integer"};if(w==="symbol")return{type:"string",description:"Symbol type"};if(w==="object")return{type:"object"};if(w.startsWith("'")||w.startsWith('"'))return{const:w.slice(1,-1)};if(/^-?\d+(\.\d+)?$/.test(w))return{const:Number.parseFloat(w)};if(w==="true")return{const:!0};if(w==="false")return{const:!1};let j=w.match(/^(.+)\[\]$/)||w.match(/^Array<(.+)>$/i);if(j)return{type:"array",items:W(j[1],g)};let E=w.match(/^\[(.+)\]$/);if(E){let Q=X(E[1],",").map((G)=>W(G.trim(),g));return{type:"array",items:Q,minItems:Q.length,maxItems:Q.length}}if(w.includes("|")){let Q=X(w,"|");if(Q.length>1){let G=Q.filter((K)=>K.trim()!=="null"&&K.trim()!=="undefined");if(Q.some((K)=>K.trim()==="null"||K.trim()==="undefined")&&G.length===1){let K=W(G[0],g);if(K.type&&typeof K.type==="string")return{...K,type:[K.type,"null"]};return{oneOf:[K,{type:"null"}]}}return{oneOf:Q.map((K)=>W(K.trim(),g))}}}if(w.includes("&")){let Q=X(w,"&");if(Q.length>1)return{allOf:Q.map((G)=>W(G.trim(),g))}}let H=w.match(/^Record<(.+),\s*(.+)>$/i);if(H)return{type:"object",additionalProperties:W(H[2],g)};let F=w.match(/^Promise<(.+)>$/i);if(F)return W(F[1],g);let L=w.match(/^Partial<(.+)>$/i);if(L)return{...W(L[1],g),required:[]};let _=w.match(/^Required<(.+)>$/i);if(_)return W(_[1],g);let P=w.match(/^Readonly<(.+)>$/i);if(P)return W(P[1],g);let $=w.match(/^Pick<(.+),\s*(.+)>$/i);if($)return W($[1],g);let D=w.match(/^Omit<(.+),\s*(.+)>$/i);if(D)return W(D[1],g);if(w==="Date")return{type:"string",format:"date-time"};if(/^[A-Z]\w*$/.test(w))return{$ref:`#/$defs/${w}`};return{type:"object"}}function Y(B,g={}){let w=g.indent??2,j=g.jsonSchemaDraft??"2020-12",E={"2020-12":"https://json-schema.org/draft/2020-12/schema","2019-09":"https://json-schema.org/draft/2019-09/schema","draft-07":"http://json-schema.org/draft-07/schema#"}[j],H=new Map,F={$schema:g.includeSchema!==!1?E:void 0,$defs:{}};for(let L of B)if(L.kind==="interface"||L.kind==="type"){let _=q(L,H,g);if(F.$defs)F.$defs[L.name]=_}if(F.$defs&&Object.keys(F.$defs).length===1){let[L,_]=Object.entries(F.$defs)[0];return JSON.stringify({$schema:F.$schema,title:L,..._},null,w)}return JSON.stringify(F,null,w)}function q(B,g,w){let j={type:"object"};if(w.includeDescriptions&&B.leadingComments?.length){let E=C(B.leadingComments);if(E)j.description=E}if(B.members&&B.members.length>0){j.properties={},j.required=[];for(let E of B.members)if(E.name&&E.typeAnnotation){let H=W(E.typeAnnotation,g);if(w.includeDescriptions&&E.leadingComments?.length){let L=C(E.leadingComments);if(L)H.description=L}if(j.properties[E.name]=H,!(E.modifiers?.includes("?")||E.text?.includes("?:")||w.allOptional))j.required.push(E.name)}if(j.required.length===0)delete j.required}else if(B.typeAnnotation)return W(B.typeAnnotation,g);return j}function k(B,g={}){let w=["import { z } from 'zod'",""];for(let j of B)if(j.kind==="interface"||j.kind==="type"){let E=g.exportName||`${j.name}Schema`,H=I(j,g);if(w.push(`export const ${E} = ${H}`),w.push(""),g.useInfer!==!1)w.push(`export type ${j.name} = z.infer<typeof ${E}>`),w.push("")}return w.join(`
`)}function I(B,g){if(B.members&&B.members.length>0)return`z.object({
${B.members.filter((j)=>j.name&&j.typeAnnotation).map((j)=>{let E=R(j.typeAnnotation);if(j.modifiers?.includes("?")||j.text?.includes("?:")||g.allOptional)E=`${E}.optional()`;if(g.includeDescriptions&&j.leadingComments?.length){let F=C(j.leadingComments);if(F)E=`${E}.describe(${JSON.stringify(F)})`}return`  ${j.name}: ${E}`}).join(`,
`)}
})`;if(B.typeAnnotation)return R(B.typeAnnotation);return"z.unknown()"}function R(B){let g=B.trim();if(g==="string")return"z.string()";if(g==="number")return"z.number()";if(g==="boolean")return"z.boolean()";if(g==="null")return"z.null()";if(g==="undefined")return"z.undefined()";if(g==="any")return"z.any()";if(g==="unknown")return"z.unknown()";if(g==="never")return"z.never()";if(g==="void")return"z.void()";if(g==="bigint")return"z.bigint()";if(g==="symbol")return"z.symbol()";if(g==="Date")return"z.date()";if(g.startsWith("'")||g.startsWith('"'))return`z.literal(${g})`;if(/^-?\d+(\.\d+)?$/.test(g))return`z.literal(${g})`;if(g==="true"||g==="false")return`z.literal(${g})`;let w=g.match(/^(.+)\[\]$/)||g.match(/^Array<(.+)>$/i);if(w)return`z.array(${R(w[1])})`;let j=g.match(/^\[(.+)\]$/);if(j)return`z.tuple([${X(j[1],",").map((D)=>R(D.trim())).join(", ")}])`;if(g.includes("|")){let $=X(g,"|");if($.length>1){let D=$.filter((K)=>K.trim()!=="null"&&K.trim()!=="undefined"),Q=$.some((K)=>K.trim()==="null"),G=$.some((K)=>K.trim()==="undefined");if((Q||G)&&D.length===1){let K=R(D[0]);if(Q)K=`${K}.nullable()`;if(G)K=`${K}.optional()`;return K}return`z.union([${$.map((K)=>R(K.trim())).join(", ")}])`}}if(g.includes("&")){let $=X(g,"&");if($.length>1)return $.map((Q)=>R(Q.trim())).reduce((Q,G)=>`${Q}.and(${G})`)}let E=g.match(/^Record<(.+),\s*(.+)>$/i);if(E)return`z.record(${R(E[1])}, ${R(E[2])})`;let H=g.match(/^Promise<(.+)>$/i);if(H)return`z.promise(${R(H[1])})`;let F=g.match(/^Map<(.+),\s*(.+)>$/i);if(F)return`z.map(${R(F[1])}, ${R(F[2])})`;let L=g.match(/^Set<(.+)>$/i);if(L)return`z.set(${R(L[1])})`;let _=g.match(/^Partial<(.+)>$/i);if(_)return`${R(_[1])}.partial()`;let P=g.match(/^Required<(.+)>$/i);if(P)return`${R(P[1])}.required()`;if(/^[A-Z]\w*$/.test(g))return`${g}Schema`;return"z.unknown()"}function V(B,g={}){let w=["import * as v from 'valibot'",""];for(let j of B)if(j.kind==="interface"||j.kind==="type"){let E=g.exportName||`${j.name}Schema`,H=J(j,g);if(w.push(`export const ${E} = ${H}`),w.push(""),g.useInfer!==!1)w.push(`export type ${j.name} = v.InferOutput<typeof ${E}>`),w.push("")}return w.join(`
`)}function J(B,g){if(B.members&&B.members.length>0)return`v.object({
${B.members.filter((j)=>j.name&&j.typeAnnotation).map((j)=>{let E=O(j.typeAnnotation);if(j.modifiers?.includes("?")||j.text?.includes("?:")||g.allOptional)E=`v.optional(${E})`;return`  ${j.name}: ${E}`}).join(`,
`)}
})`;if(B.typeAnnotation)return O(B.typeAnnotation);return"v.unknown()"}function O(B){let g=B.trim();if(g==="string")return"v.string()";if(g==="number")return"v.number()";if(g==="boolean")return"v.boolean()";if(g==="null")return"v.null_()";if(g==="undefined")return"v.undefined_()";if(g==="any")return"v.any()";if(g==="unknown")return"v.unknown()";if(g==="never")return"v.never()";if(g==="void")return"v.void_()";if(g==="bigint")return"v.bigint()";if(g==="symbol")return"v.symbol()";if(g==="Date")return"v.date()";if(g.startsWith("'")||g.startsWith('"'))return`v.literal(${g})`;if(/^-?\d+(\.\d+)?$/.test(g))return`v.literal(${g})`;if(g==="true"||g==="false")return`v.literal(${g})`;let w=g.match(/^(.+)\[\]$/)||g.match(/^Array<(.+)>$/i);if(w)return`v.array(${O(w[1])})`;let j=g.match(/^\[(.+)\]$/);if(j)return`v.tuple([${X(j[1],",").map((F)=>O(F.trim())).join(", ")}])`;if(g.includes("|")){let H=X(g,"|");if(H.length>1){let F=H.filter((P)=>P.trim()!=="null"&&P.trim()!=="undefined"),L=H.some((P)=>P.trim()==="null"),_=H.some((P)=>P.trim()==="undefined");if((L||_)&&F.length===1){let P=O(F[0]);if(L)P=`v.nullable(${P})`;if(_)P=`v.optional(${P})`;return P}return`v.union([${H.map((P)=>O(P.trim())).join(", ")}])`}}if(g.includes("&")){let H=X(g,"&");if(H.length>1)return`v.intersect([${H.map((F)=>O(F.trim())).join(", ")}])`}let E=g.match(/^Record<(.+),\s*(.+)>$/i);if(E)return`v.record(${O(E[1])}, ${O(E[2])})`;if(/^[A-Z]\w*$/.test(g))return`${g}Schema`;return"v.unknown()"}function Z(B,g={}){let w=["import * as t from 'io-ts'",""];for(let j of B)if(j.kind==="interface"||j.kind==="type"){let E=g.exportName||`${j.name}Codec`,H=U(j,g);if(w.push(`export const ${E} = ${H}`),w.push(""),g.useInfer!==!1)w.push(`export type ${j.name} = t.TypeOf<typeof ${E}>`),w.push("")}return w.join(`
`)}function U(B,g){if(B.members&&B.members.length>0){let w=[],j=[];for(let E of B.members){if(!E.name||!E.typeAnnotation)continue;let H=v(E.typeAnnotation),F=E.modifiers?.includes("?")||E.text?.includes("?:")||g.allOptional,L=`  ${E.name}: ${H}`;if(F)j.push(L);else w.push(L)}if(j.length>0)return`t.intersection([
  t.type({
${w.join(`,
`)}
  }),
  t.partial({
${j.join(`,
`)}
  })
])`;return`t.type({
${w.join(`,
`)}
})`}if(B.typeAnnotation)return v(B.typeAnnotation);return"t.unknown"}function v(B){let g=B.trim();if(g==="string")return"t.string";if(g==="number")return"t.number";if(g==="boolean")return"t.boolean";if(g==="null")return"t.null";if(g==="undefined")return"t.undefined";if(g==="any")return"t.unknown";if(g==="unknown")return"t.unknown";if(g==="never")return"t.never";if(g==="void")return"t.void";if(g.startsWith("'")||g.startsWith('"'))return`t.literal(${g})`;if(/^-?\d+(\.\d+)?$/.test(g))return`t.literal(${g})`;if(g==="true"||g==="false")return`t.literal(${g})`;let w=g.match(/^(.+)\[\]$/)||g.match(/^Array<(.+)>$/i);if(w)return`t.array(${v(w[1])})`;let j=g.match(/^\[(.+)\]$/);if(j)return`t.tuple([${X(j[1],",").map((F)=>v(F.trim())).join(", ")}])`;if(g.includes("|")){let H=X(g,"|");if(H.length>1)return`t.union([${H.map((F)=>v(F.trim())).join(", ")}])`}if(g.includes("&")){let H=X(g,"&");if(H.length>1)return`t.intersection([${H.map((F)=>v(F.trim())).join(", ")}])`}let E=g.match(/^Record<(.+),\s*(.+)>$/i);if(E)return`t.record(${v(E[1])}, ${v(E[2])})`;if(/^[A-Z]\w*$/.test(g))return`${g}Codec`;return"t.unknown"}function N(B,g={}){let w=["import * as yup from 'yup'",""];for(let j of B)if(j.kind==="interface"||j.kind==="type"){let E=g.exportName||`${j.name}Schema`,H=S(j,g);if(w.push(`export const ${E} = ${H}`),w.push(""),g.useInfer!==!1)w.push(`export type ${j.name} = yup.InferType<typeof ${E}>`),w.push("")}return w.join(`
`)}function S(B,g){if(B.members&&B.members.length>0)return`yup.object({
${B.members.filter((j)=>j.name&&j.typeAnnotation).map((j)=>{let E=x(j.typeAnnotation);if(!(j.modifiers?.includes("?")||j.text?.includes("?:")||g.allOptional))E=`${E}.required()`;return`  ${j.name}: ${E}`}).join(`,
`)}
})`;if(B.typeAnnotation)return x(B.typeAnnotation);return"yup.mixed()"}function x(B){let g=B.trim();if(g==="string")return"yup.string()";if(g==="number")return"yup.number()";if(g==="boolean")return"yup.boolean()";if(g==="Date")return"yup.date()";if(g==="any"||g==="unknown")return"yup.mixed()";let w=g.match(/^(.+)\[\]$/)||g.match(/^Array<(.+)>$/i);if(w)return`yup.array().of(${x(w[1])})`;if(g.includes("|")){let j=X(g,"|");if(j.length>1){let E=j.filter((F)=>F.trim()!=="null"&&F.trim()!=="undefined");if(j.some((F)=>F.trim()==="null"||F.trim()==="undefined")&&E.length===1)return`${x(E[0])}.nullable()`}}if(/^[A-Z]\w*$/.test(g))return`${g}Schema`;return"yup.mixed()"}function f(B,g={}){let w=["import { type } from 'arktype'",""];for(let j of B)if(j.kind==="interface"||j.kind==="type"){let E=g.exportName||j.name,H=u(j,g);if(w.push(`export const ${E} = ${H}`),w.push(""),g.useInfer!==!1)w.push(`export type ${j.name}Type = typeof ${E}.infer`),w.push("")}return w.join(`
`)}function u(B,g){if(B.members&&B.members.length>0)return`type({
${B.members.filter((j)=>j.name&&j.typeAnnotation).map((j)=>{let E=A(j.typeAnnotation);return`  ${j.modifiers?.includes("?")||j.text?.includes("?:")||g.allOptional?`'${j.name}?'`:`${j.name}`}: ${E}`}).join(`,
`)}
})`;if(B.typeAnnotation)return`type(${A(B.typeAnnotation)})`;return"type('unknown')"}function A(B){let g=B.trim();if(g==="string")return"'string'";if(g==="number")return"'number'";if(g==="boolean")return"'boolean'";if(g==="null")return"'null'";if(g==="undefined")return"'undefined'";if(g==="bigint")return"'bigint'";if(g==="symbol")return"'symbol'";if(g==="Date")return"'Date'";if(g==="any"||g==="unknown")return"'unknown'";let w=g.match(/^(.+)\[\]$/)||g.match(/^Array<(.+)>$/i);if(w)return`${A(w[1])}.array()`;if(g.includes("|")){let j=X(g,"|");if(j.length>1)return`'${j.map((E)=>E.trim()).join(" | ")}'`}if(g.startsWith("'")||g.startsWith('"'))return`'${g}'`;return`'${g}'`}function X(B,g){let w=[],j="",E=0;for(let H=0;H<B.length;H++){let F=B[H];if(F==="<"||F==="("||F==="["||F==="{")E++,j+=F;else if(F===">"||F===")"||F==="]"||F==="}")E--,j+=F;else if(E===0&&B.slice(H,H+g.length)===g)w.push(j.trim()),j="",H+=g.length-1;else j+=F}if(j.trim())w.push(j.trim());return w}function C(B){for(let g of B){let w=g.replace(/^\/\*\*|\*\/$/g,"").replace(/^\s*\*\s?/gm,"").replace(/@\w.*/g,"").trim();if(w)return w}return null}function M(B,g){switch(g.format){case"json-schema":return Y(B,g);case"zod":return k(B,g);case"valibot":return V(B,g);case"io-ts":return Z(B,g);case"yup":return N(B,g);case"arktype":return f(B,g);case"dts":default:return B.map((w)=>w.text).join(`

`)}}function b(B){switch(B){case"json-schema":return".schema.json";case"zod":case"valibot":case"io-ts":case"yup":case"arktype":return".schema.ts";case"dts":default:return".d.ts"}}
export{Y as I,k as J,V as K,Z as L,N as M,f as N,M as O,b as P};
