import { createInsertSchema, createSelectSchema } from "drizzle-zod"; import { z } from "zod"; import { pageComponentImpact } from "./constants"; import { pageComponent, statusReportUpdateToPageComponents, } from "./page_components"; export const selectPageComponentSchema = createSelectSchema(pageComponent); export const insertPageComponentSchema = createInsertSchema(pageComponent, { name: z.string().min(1), }).refine( (data) => { // monitorId must be set when type='monitor' if (data.type === "monitor" && !data.monitorId) { return false; } // monitorId must be null when type='static' if (data.type === "static" && data.monitorId) { return false; } return true; }, { message: "monitorId must be set when type is 'monitor' and must be null when type is 'static'", }, ); export type InsertPageComponent = z.infer; export type PageComponent = z.infer; export const pageComponentImpactSchema = z.enum(pageComponentImpact); export const selectStatusReportUpdateToPageComponentSchema = createSelectSchema( statusReportUpdateToPageComponents, { impact: pageComponentImpactSchema }, ); export const insertStatusReportUpdateToPageComponentSchema = createInsertSchema( statusReportUpdateToPageComponents, { impact: pageComponentImpactSchema }, ); export type StatusReportUpdateToPageComponent = z.infer< typeof selectStatusReportUpdateToPageComponentSchema >;