package com.correx.core.artifacts.kind

import kotlinx.serialization.Serializable

@Serializable
data class JsonSchema(
    val type: String,
    val properties: Map<String, JsonSchemaProperty> = emptyMap(),
    val required: List<String> = emptyList(),
    val additionalProperties: Boolean = false,
)

@Serializable
data class JsonSchemaProperty(
    val type: String,
    val description: String = "",
    val default: String? = null,
    // For `type == "array"`: minimum element count (0 = unconstrained) and the element
    // schema. Lets a schema declare a required-non-empty list — the deterministic guard
    // behind the role pipeline's "define done" contract (an empty `requirements`/`steps`
    // array is a misread brief, not a valid artifact).
    val minItems: Int = 0,
    val items: JsonSchemaProperty? = null,
    // For `type == "object"` (either a nested property or an array's `items`): the object's
    // own shape. Lets a schema describe structured collections — e.g. the discovery stage's
    // `questions: array of { prompt, options, header, ... }`. Without this the parser rejects
    // any nested object schema ("unknown key 'properties'"), silently dropping the kind.
    // JSON-schema convention: nested objects allow extra keys by default (additionalProperties=true),
    // unlike the top-level [JsonSchema] which defaults to strict.
    val properties: Map<String, JsonSchemaProperty> = emptyMap(),
    val required: List<String> = emptyList(),
    val additionalProperties: Boolean = true,
)
