/**
 * AI Agent Node - Version 1.7 - Zod Validation Schemas
 *
 * These schemas validate node configuration at runtime.
 * Use .parse() for strict validation or .safeParse() for error handling.
 *
 * Schema helpers (z, expressionSchema, etc.) are passed as parameters
 * by the schema-validator, not imported from external files.
 *
 * @generated - CommonJS JavaScript for runtime loading
 */

module.exports = function getSchema({ parameters, z, expressionSchema, stringOrExpression, numberOrExpression, booleanOrExpression, resourceLocatorValueSchema, resourceMapperValueSchema, filterValueSchema, assignmentCollectionValueSchema, iDataObjectSchema, resolveSchema, languageModelInstanceSchema, memoryInstanceSchema, toolInstanceSchema, outputParserInstanceSchema }) {

  // Helper function for conditional subnode schema
  function getSubnodesSchema() {
    return z.object({
      model: z.union([languageModelInstanceSchema, z.array(languageModelInstanceSchema)]),
      memory: memoryInstanceSchema.optional(),
      tools: z.array(toolInstanceSchema).optional(),
      outputParser: resolveSchema({ parameters, schema: outputParserInstanceSchema, required: false, displayOptions: {"show":{"hasOutputParser":[true]}}, defaults: {"hasOutputParser":false} }),
    }).strict();
  }

  // Parameters schema
  const parametersSchema = z.object({
    agent: z.union([z.literal('conversationalAgent'), z.literal('openAiFunctionsAgent'), z.literal('planAndExecuteAgent'), z.literal('reActAgent'), z.literal('sqlAgent')]).optional(),
    promptType: resolveSchema({ parameters, schema: z.union([z.literal('auto'), z.literal('guardrails'), z.literal('define'), expressionSchema]), required: false, displayOptions: {"show":{"agent":["sqlAgent"]},"hide":{"agent":["sqlAgent"]}}, defaults: {"agent":"conversationalAgent"} }),
    text: resolveSchema({ parameters, schema: stringOrExpression, required: false, displayOptions: {"show":{"promptType":["guardrails","auto","define"],"agent":["sqlAgent"]},"hide":{"agent":["sqlAgent"]}}, defaults: {"promptType":"auto","agent":"conversationalAgent"} }),
    hasOutputParser: resolveSchema({ parameters, schema: z.boolean(), required: false, displayOptions: {"hide":{"agent":["sqlAgent"]}}, defaults: {"agent":"conversationalAgent"} }),
    options: resolveSchema({ parameters, schema: z.object({ systemMessage: stringOrExpression.optional(), maxIterations: numberOrExpression.optional(), returnIntermediateSteps: booleanOrExpression.optional(), passthroughBinaryImages: booleanOrExpression.optional(), tracingMetadata: z.object({ values: z.array(z.object({ key: stringOrExpression.optional(), type: z.union([z.literal('arrayValue'), z.literal('booleanValue'), z.literal('numberValue'), z.literal('objectValue'), z.literal('stringValue'), expressionSchema]).optional(), stringValue: stringOrExpression.optional(), numberValue: stringOrExpression.optional(), booleanValue: z.union([z.literal('true'), z.literal('false'), expressionSchema]).optional(), arrayValue: stringOrExpression.optional(), objectValue: z.union([iDataObjectSchema, z.string()]).optional() })).optional() }).optional(), humanMessage: stringOrExpression.optional(), humanMessageTemplate: stringOrExpression.optional(), prefix: stringOrExpression.optional(), suffixChat: stringOrExpression.optional(), suffix: stringOrExpression.optional(), ignoredTables: stringOrExpression.optional(), includedSampleRows: numberOrExpression.optional(), includedTables: stringOrExpression.optional(), prefixPrompt: stringOrExpression.optional(), suffixPrompt: stringOrExpression.optional(), topK: numberOrExpression.optional() }), required: false, displayOptions: {"show":{"agent":["toolsAgent","conversationalAgent","openAiFunctionsAgent","reActAgent","sqlAgent","planAndExecuteAgent"]}}, defaults: {"agent":"conversationalAgent"} }),
    dataSource: resolveSchema({ parameters, schema: z.union([z.literal('mysql'), z.literal('postgres'), z.literal('sqlite'), expressionSchema]), required: false, displayOptions: {"show":{"agent":["sqlAgent"]}}, defaults: {"agent":"conversationalAgent"} }),
    binaryPropertyName: resolveSchema({ parameters, schema: stringOrExpression, required: false, displayOptions: {"show":{"agent":["sqlAgent"],"dataSource":["sqlite"]}}, defaults: {"agent":"conversationalAgent","dataSource":"postgres"} }),
  });

  // Return combined config schema
  return z.object({
    parameters: parametersSchema.nullable().optional(),
    subnodes: getSubnodesSchema(),
  });
};