import { z } from 'zod';
import { UnitType, DashboardVisualisationSchema, DashboardColumns } from '../../../_dashboards/dashboard-visualisation/Validate.js';

const BarMeasureShema = z.object({
    id: z.string(),
    display: z.string().optional(),
    unit: z.enum(UnitType).optional(),
    axis: z.enum(['x', 'y']).optional(),
});
const BarOptionsSchema = z.object({
    showLatest: z.boolean().default(true),
    horizontal: z.boolean().default(false),
    xStacked: z.boolean().default(false),
    yStacked: z.boolean().default(false),
});
const BarMeasuresSchema = 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.object({
    ...DashboardVisualisationSchema.shape,
    type: z.literal('bar'),
    display: z.string(),
    options: z.object(BarOptionsSchema.shape).optional(),
    columns: z.object({
        ...DashboardColumns.shape,
        measures: BarMeasuresSchema,
    }),
});
const BarChartSchemas = {
    BarSchema,
    BarMeasuresSchema,
};

export { BarChartSchemas as default };
//# sourceMappingURL=validate.js.map
