import { z } from '@hono/zod-openapi'

export const ErrorSchema = z.object({
  code: z.number().openapi({
    example: 400,
  }),
  message: z.string().openapi({
    example: 'Bad Request',
  }),
})

// Zod错误详情schema - 类型安全版本
export const ZodIssueSchema = z.object({
  code: z.string().openapi({
    example: 'invalid_type',
  }),
  expected: z.string().optional().openapi({
    example: 'number',
  }),
  received: z.string().optional().openapi({
    example: 'string',
  }),
  path: z.array(z.union([z.string(), z.number(), z.null()])).openapi({
    example: ['basicSalary'],
  }),
  message: z.string().openapi({
    example: '基本工资必须大于0',
  }),
  origin: z.string().optional().openapi({
    example: 'value',
  }),
  minimum: z.number().optional().openapi({
    example: 0,
  }),
  maximum: z.number().optional().openapi({
    example: 100,
  }),
  inclusive: z.boolean().optional().openapi({
    example: false,
  }),
  // 添加更多可能的字段
  input: z.any().optional().openapi({
    description: '原始输入数据（当reportInput为true时）',
  }),
  fatal: z.boolean().optional().openapi({
    example: false,
  }),
  type: z.string().optional().openapi({
    example: 'string',
  }),
  exact: z.boolean().optional().openapi({
    example: false,
  }),
  validation: z.string().optional().openapi({
    example: 'email',
  }),
  keys: z.array(z.string()).optional().openapi({
    example: ['extraField'],
  }),
  options: z.array(z.union([z.string(), z.number()])).optional().openapi({
    example: ['option1', 'option2'],
  }),
  multipleOf: z.number().optional().openapi({
    example: 5,
  }),
  unionErrors: z.array(z.any()).optional().openapi({
    description: '联合类型错误详情',
  }),
  argumentsError: z.any().optional().openapi({
    description: '参数错误详情',
  }),
  returnTypeError: z.any().optional().openapi({
    description: '返回类型错误详情',
  }),
})

// Zod错误响应schema
export const ZodErrorSchema = z.object({
  code: z.number().openapi({
    example: 400,
  }),
  message: z.string().openapi({
    example: '参数错误',
  }),
  errors: z.array(ZodIssueSchema).openapi({
    description: 'Zod验证错误详情',
  }),
})
