import { LixSchemaViewMap } from "../schema-view-map.js";
import { isJsonType } from "../../schema-definition/json-type.js";
export function buildJsonColumnConfig(args) {
    const includeChangeView = args?.includeChangeView ?? true;
    const result = {};
    const fileJsonColumns = {
        metadata: { type: "object" },
    };
    const hardcoded = {
        state: {
            snapshot_content: { type: "object" },
            metadata: { type: "object" },
        },
        state_by_version: {
            snapshot_content: { type: "object" },
            metadata: { type: "object" },
        },
        state_history: {
            snapshot_content: { type: "object" },
            metadata: { type: "object" },
        },
        // hardcoded special handling for file views
        file: fileJsonColumns,
        file_by_version: fileJsonColumns,
        file_history: fileJsonColumns,
    };
    if (includeChangeView) {
        hardcoded.change = {
            snapshot_content: { type: "object" },
            metadata: { type: "object" },
        };
    }
    Object.assign(result, hardcoded);
    for (const [viewName, schema] of Object.entries(LixSchemaViewMap)) {
        if (typeof schema === "boolean" || !schema.properties)
            continue;
        const jsonColumns = {};
        for (const [key, def] of Object.entries(schema.properties)) {
            if (isJsonType(def)) {
                jsonColumns[key] = {
                    type: ["string", "number", "boolean", "object", "array", "null"],
                };
            }
        }
        // All entity views expose lixcol_metadata as a JSON column sourced from change metadata.
        jsonColumns.lixcol_metadata = { type: "object" };
        if (Object.keys(jsonColumns).length > 0) {
            result[viewName] = jsonColumns;
            result[viewName + "_by_version"] = jsonColumns;
            result[viewName + "_history"] = jsonColumns;
        }
    }
    return result;
}
//# sourceMappingURL=json-column-config.js.map