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

import { z } from "zod";

{%- set current_type = "" -%}
{%- for row in sparql_results -%}
{%- set entityName = row["?entityName"] | default(value="") -%}
{%- set operationType = row["?operationType"] | 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 type_name = "" -%}
{%- if operationType == "create" -%}
{%- set type_name = "create" ~ entityName ~ "Request" -%}
{%- elif operationType == "update" -%}
{%- set type_name = "update" ~ entityName ~ "Request" -%}
{%- endif -%}

{%- if type_name != "" and type_name != current_type -%}
{%- if current_type != "" %}
});

/**
 * @typedef {z.infer<typeof {{ current_type }}Schema>} {{ current_type | capitalize }}Type
 */

{% endif -%}
{%- set_global current_type = type_name %}
/**
 * {{ type_name }} validation schema
 */
export const {{ type_name }}Schema = z.object({
{%- endif %}
{%- if type_name != "" %}
  {{ propertyName }}: {% if propertyType == "string" %}z.string(){% if minLength != "" %}.min({{ minLength }}){% endif %}{% if maxLength != "" %}.max({{ maxLength }}){% endif %}{% elif propertyType == "integer" %}z.number().int(){% elif propertyType == "number" %}z.number(){% elif propertyType == "boolean" %}z.boolean(){% else %}z.string(){% endif %}{% if required != "true" %}.optional(){% endif %},
{%- endif %}
{%- endfor %}
});

/**
 * @typedef {z.infer<typeof {{ current_type }}Schema>} {{ current_type | capitalize }}Type
 */
