{# =============================================================================
   ZOD SCHEMAS TEMPLATE - Generates Zod validation schemas
   Uses sparql_results array with ?-prefixed keys
   ============================================================================= #}
/**
 * @fileoverview Generated Zod schemas from RDF ontology
 * DO NOT EDIT - auto-generated by ggen sync
 * @module generated/schemas
 */

import { z } from "zod";

{%- set current_entity = "" -%}
{%- for row in sparql_results -%}
{%- set entityName = row["?entityName"] | default(value="") -%}
{%- set entityDescription = row["?entityDescription"] | default(value="") -%}
{%- set propertyName = row["?propertyName"] | default(value="") -%}
{%- set propertyType = row["?propertyType"] | default(value="string") -%}
{%- set required = row["?required"] | default(value="false") -%}
{%- set minLength = row["?minLength"] | default(value="") -%}
{%- set maxLength = row["?maxLength"] | default(value="") -%}
{%- set format = row["?format"] | default(value="") -%}
{%- set refEntity = row["?refEntity"] | default(value="") -%}

{%- if entityName != current_entity -%}
{%- if current_entity != "" %}
});

/**
 * @typedef {z.infer<typeof {{ current_entity | lower }}Schema>} {{ current_entity }}
 */

{% endif -%}
{%- set_global current_entity = entityName %}
/**
 * {{ entityName }} schema{% if entityDescription != "" %} - {{ entityDescription }}{% endif %}

 */
export const {{ entityName | lower }}Schema = z.object({
{%- endif %}
  {{ propertyName }}: {% if propertyType == "string" %}z.string(){% if minLength != "" %}.min({{ minLength }}){% endif %}{% if maxLength != "" %}.max({{ maxLength }}){% endif %}{% if format == "email" %}.email("Must be a valid email address"){% endif %}{% elif propertyType == "integer" %}z.number().int(){% elif propertyType == "number" %}z.number(){% elif propertyType == "boolean" %}z.boolean(){% elif propertyType == "datetime" %}z.string().datetime("Must be ISO 8601 datetime"){% elif propertyType == "date" %}z.string(){% elif propertyType == "reference" %}z.lazy(() => z.array({{ refEntity | lower }}Schema)).default([]){% else %}z.string(){% endif %}{% if required != "true" %}.optional().nullable(){% endif %},
{%- endfor %}
});

/**
 * @typedef {z.infer<typeof {{ current_entity | lower }}Schema>} {{ current_entity }}
 */
