"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateApiConfig = generateApiConfig;
function generateApiConfig({ backend: { modules } }) {
    return /*ts*/ `
import z from 'zod'

const zEnvBoolean = z.union([
  //
  z.literal('true').transform(() => true),
  z.literal('false').transform(() => false),
])
  
export const zApiConfigSchema = z
  .object({
    API_PORT: z.coerce.number().int(),
    API_URL: z
      .string()
      .url()
      .transform((val) => new URL(val)),
    API_PREFIX: z.string().default(''),

    APP_SECRET: z.string(),
    ALLOW_ORIGIN: z.string().optional().default('*'),

    FRONTEND_URL: z
    .string()
    .url()
    .transform((val) => new URL(val))
    .optional(),

    STATEFUL: zEnvBoolean.optional().default(true),
    ALLOW_ADMIN_BACKEND: zEnvBoolean.optional().default(false),

    ${modules
        .filter((m) => m.envConfig)
        .map((m) => `${removeTrailingComma(m.envConfig.decoder)}`)
        .filter((m) => m !== '')
        .join(',\n')}
  })

  .transform((val) => ({
    port: val.API_PORT,
    url: val.API_URL,
    urlPrefix: val.API_PREFIX,
    frontendUrl: val.FRONTEND_URL,
    appSecret: val.APP_SECRET,
    allowOrigin: val.ALLOW_ORIGIN,

    admin: {
      allowBackend: val.ALLOW_ADMIN_BACKEND,
    },

    ${modules
        .filter((m) => m.envConfig)
        .map((m) => `${removeTrailingComma(m.envConfig.transformer)}`)
        .join(',\n')}
    
  }))

export type ApiConfig = z.infer<typeof zApiConfigSchema>  
  
${modules
        .filter((m) => m.envConfig?.type)
        .map((m) => `${removeTrailingComma(m.envConfig.type)}`) // NOSONAR - false positive, type assertion is needed
        .join('\n')}
`;
}
function removeTrailingComma(input) {
    return input.replace(/,\s*$/, '');
}
//# sourceMappingURL=api-config.generator.js.map