export function enforceStrictSchema(schema) {
    if (!schema || typeof schema !== "object" || Array.isArray(schema)) {
        return schema;
    }
    const result = { ...schema };
    // If it's an object type, apply strict rules
    if (result.type === "object") {
        // 1. additionalProperties must be false (or set to false if omitted)
        if (!("additionalProperties" in result)) {
            result.additionalProperties = false;
        }
        // 2. All properties must be listed in the required array
        if (result.properties && typeof result.properties === "object") {
            const keys = Object.keys(result.properties);
            if (keys.length > 0) {
                const existingRequired = Array.isArray(result.required) ? result.required : [];
                const requiredSet = new Set([...existingRequired, ...keys]);
                result.required = Array.from(requiredSet);
            }
            // Recursively apply to all properties
            const newProps = {};
            for (const [key, propSchema] of Object.entries(result.properties)) {
                newProps[key] = enforceStrictSchema(propSchema);
            }
            result.properties = newProps;
        }
    }
    // Handle arrays recursively
    if (result.type === "array" && result.items && typeof result.items === "object") {
        result.items = enforceStrictSchema(result.items);
    }
    // Handle nested schemas in anyOf, allOf, oneOf
    for (const compound of ["anyOf", "allOf", "oneOf"]) {
        if (Array.isArray(result[compound])) {
            result[compound] = result[compound].map(enforceStrictSchema);
        }
    }
    return result;
}
