"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DashboardAsCodeInternalization = void 0;
const zod_1 = require("zod");
const dashboard_1 = require("../../types/dashboard");
const abstract_1 = require("./abstract");
const merge_1 = require("./merge");
const dashboardAsCodeSchema = zod_1.z.object({
    name: zod_1.z.string(),
    description: zod_1.z
        .string()
        .nullable()
        .optional()
        .transform((str) => str ?? undefined),
    tiles: zod_1.z.array(zod_1.z.union([
        zod_1.z.object({
            type: zod_1.z.union([
                zod_1.z.literal(dashboard_1.DashboardTileTypes.SAVED_CHART),
                zod_1.z.literal(dashboard_1.DashboardTileTypes.SQL_CHART),
            ]),
            properties: zod_1.z.object({
                title: zod_1.z.string(),
                chartName: zod_1.z.string().optional().default(''),
            }),
        }),
        zod_1.z.object({
            type: zod_1.z.literal(dashboard_1.DashboardTileTypes.MARKDOWN),
            properties: zod_1.z.object({
                title: zod_1.z.string(),
                content: zod_1.z.string(),
            }),
        }),
        zod_1.z.object({
            type: zod_1.z.literal(dashboard_1.DashboardTileTypes.LOOM),
            properties: zod_1.z.object({
                title: zod_1.z.string(),
            }),
        }),
        zod_1.z.object({
            type: zod_1.z.literal(dashboard_1.DashboardTileTypes.HEADING),
            properties: zod_1.z.object({
                text: zod_1.z.string(),
            }),
        }),
        zod_1.z.object({
            type: zod_1.z.literal(dashboard_1.DashboardTileTypes.DATA_APP),
            properties: zod_1.z.object({
                title: zod_1.z.string(),
            }),
        }),
    ])),
});
class DashboardAsCodeInternalization extends abstract_1.AsCodeInternalization {
    constructor(schema = dashboardAsCodeSchema) {
        super();
        this.schema = schema;
    }
    getLanguageMap(dashboardAsCode) {
        return {
            dashboard: {
                [dashboardAsCode.slug]: this.schema
                    .deepPartial()
                    .strip()
                    .parse(dashboardAsCode),
            },
        };
    }
    // eslint-disable-next-line class-methods-use-this
    merge(internalizationMap, content) {
        return (0, merge_1.mergeExisting)(content, internalizationMap);
    }
}
exports.DashboardAsCodeInternalization = DashboardAsCodeInternalization;
//# sourceMappingURL=dashboardAsCode.js.map