import { z } from 'zod';
import { DashboardTileTypes } from '../../types/dashboard';
import { AsCodeInternalization } from './abstract';
import { mergeExisting } from './merge';
const dashboardAsCodeSchema = z.object({
    name: z.string(),
    description: z
        .string()
        .nullable()
        .optional()
        .transform((str) => str ?? undefined),
    tiles: z.array(z.union([
        z.object({
            type: z.union([
                z.literal(DashboardTileTypes.SAVED_CHART),
                z.literal(DashboardTileTypes.SQL_CHART),
            ]),
            properties: z.object({
                title: z.string(),
                chartName: z.string().optional().default(''),
            }),
        }),
        z.object({
            type: z.literal(DashboardTileTypes.MARKDOWN),
            properties: z.object({
                title: z.string(),
                content: z.string(),
            }),
        }),
        z.object({
            type: z.literal(DashboardTileTypes.LOOM),
            properties: z.object({
                title: z.string(),
            }),
        }),
        z.object({
            type: z.literal(DashboardTileTypes.HEADING),
            properties: z.object({
                text: z.string(),
            }),
        }),
        z.object({
            type: z.literal(DashboardTileTypes.DATA_APP),
            properties: z.object({
                title: z.string(),
            }),
        }),
    ])),
});
export class DashboardAsCodeInternalization extends 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 mergeExisting(content, internalizationMap);
    }
}
//# sourceMappingURL=dashboardAsCode.js.map