import { z } from 'zod'

export const dataQualityStatusSchema = z.enum(['PASS', 'WARN', 'QUARANTINED'])

export const dataQualityRunSchema = z.object({
  runId: z.string().uuid(),
  source: z.string().min(1),
  session: z.string().min(1),
  status: dataQualityStatusSchema,
  rowCount: z.number().int().nonnegative(),
  failedRows: z.number().int().nonnegative(),
  sourceWatermark: z.string().min(1),
  datasetId: z.string().min(1),
  contentHash: z.string().min(1),
  completedAt: z.string().datetime({ offset: true })
}).superRefine((value, ctx) => {
  if (value.failedRows > value.rowCount) {
    ctx.addIssue({
      code: z.ZodIssueCode.custom,
      message: '실패 행 수는 전체 행 수를 초과할 수 없습니다.',
      path: ['failedRows']
    })
  }
})

export const dataQualityRunsSchema = z.array(dataQualityRunSchema)
export type DataQualityRun = z.infer<typeof dataQualityRunSchema>
