'use strict';

var z = require('zod');
var Validate = require('../../../_dashboards/dashboard-visualisation/Validate.js');

const BarMeasureShema = z.z.object({
    id: z.z.string(),
    display: z.z.string().optional(),
    unit: z.z.enum(Validate.UnitType).optional(),
    axis: z.z.enum(['x', 'y']).optional(),
});
const BarOptionsSchema = z.z.object({
    showLatest: z.z.boolean().default(true),
    horizontal: z.z.boolean().default(false),
    xStacked: z.z.boolean().default(false),
    yStacked: z.z.boolean().default(false),
});
const BarMeasuresSchema = z.z
    .array(BarMeasureShema)
    .refine((measures) => {
    const xAxis = measures.find((m) => m.axis === 'x');
    const yAxis = measures.find((m) => m.axis === 'y');
    let valid = true;
    if ((xAxis !== undefined && !yAxis) || (yAxis !== undefined && !xAxis)) {
        valid = false;
    }
    return valid;
}, { error: 'X and Y axis must be defined in measure' })
    .refine((measures) => {
    const xAxis = measures.find((m) => m.axis === 'x');
    const yAxis = measures.find((m) => m.axis === 'y');
    let valid = true;
    if (xAxis !== undefined && yAxis !== undefined && measures.length > 2)
        valid = false;
    return valid;
}, { error: 'Measure must contain only 2 items when axis is specified' });
const BarSchema = z.z.object({
    ...Validate.DashboardVisualisationSchema.shape,
    type: z.z.literal('bar'),
    display: z.z.string(),
    options: z.z.object(BarOptionsSchema.shape).optional(),
    columns: z.z.object({
        ...Validate.DashboardColumns.shape,
        measures: BarMeasuresSchema,
    }),
});
const BarChartSchemas = {
    BarSchema,
    BarMeasuresSchema,
};

module.exports = BarChartSchemas;
//# sourceMappingURL=validate.js.map
