import { z } from 'zod'

export const logTypeSchema = z.enum(['operation', 'verification', 'exception'])
export const logStatusSchema = z.enum(['success', 'failed'])

export const logSchema = z.object({
  id: z.union([z.string(), z.number()]),
  log_type: logTypeSchema,
  action: z.string(),
  resource: z.string().optional().nullable(),
  resource_id: z.union([z.string(), z.number()]).optional().nullable(),
  details: z.string(),
  status: logStatusSchema,
  ip_address: z.string(),
  user_agent: z.string().optional().nullable(),
  device_id: z.string().optional().nullable(),
  level: z.string().optional().nullable(),
  error_message: z.string().optional().nullable(),
  application_id: z.union([z.string(), z.number()]).optional().nullable(),
  user_id: z.union([z.string(), z.number()]).optional().nullable(),
  app_user_id: z.union([z.string(), z.number()]).optional().nullable(),
  created_at: z.string(),
  application: z.object({
    id: z.union([z.string(), z.number()]),
    name: z.string(),
  }).optional().nullable(),
  user: z.object({
    id: z.union([z.string(), z.number()]),
    username: z.string(),
  }).optional().nullable(),
  app_user: z.object({
    id: z.union([z.string(), z.number()]),
    username: z.string(),
  }).optional().nullable(),
})

export type Log = z.infer<typeof logSchema>
