import { isJsonType } from "../../schema-definition/json-type.js";
/**
 * Builds a json_object entries list for snapshot_content serialization that respects schema types.
 * - For JSON-like props (object/array): accept raw JSON when valid, otherwise quote
 * - For string props: always json_quote to avoid coercion (e.g. "1.0" -> 1)
 * - For others (number/boolean/null): generic JSON handling
 */
export function buildJsonObjectEntries(args) {
    const properties = Object.keys(args.schema.properties);
    return properties
        .map((prop) => {
        const def = args.schema.properties[prop];
        const ref = () => args.ref(prop);
        const jsonLike = isJsonType(def);
        const types = def?.type
            ? Array.isArray(def.type)
                ? def.type
                : [def.type]
            : [];
        const isString = !jsonLike && types.includes("string");
        if (jsonLike) {
            const first = ref();
            const second = ref();
            const third = ref();
            return `'${prop}', CASE WHEN json_valid(${first}) THEN json(${second}) ELSE json_quote(${third}) END`;
        }
        if (isString) {
            return `'${prop}', json_quote(${ref()})`;
        }
        const first = ref();
        const second = ref();
        const third = ref();
        return `'${prop}', CASE WHEN json_valid(${first}) THEN json(${second}) ELSE json_quote(${third}) END`;
    })
        .join(", ");
}
//# sourceMappingURL=build-json-object-entries.js.map