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

export const SupplierSchema = z.object({
  id: z.number().int().positive().openapi({ description: '供应商ID' }),
  name: z.string().min(1, '供货商名称不能为空').max(255, '供货商名称最多255个字符').nullable().openapi({
    description: '供货商名称',
    example: '供应商A'
  }),
  username: z.string().min(1, '用户名不能为空').max(20, '用户名最多20个字符').openapi({
    description: '用户名',
    example: 'supplier001'
  }),
  password: z.string().min(6, '密码至少6位').max(255, '密码最多255位').openapi({
    description: '密码',
    example: 'password123'
  }),
  phone: z.string().regex(/^1[3-9]\d{9}$/, '请输入正确的手机号').nullable().optional().openapi({
    description: '手机号码',
    example: '13800138000'
  }),
  realname: z.string().max(20, '姓名最多20个字符').nullable().optional().openapi({
    description: '姓名',
    example: '张三'
  }),
  loginNum: z.number().int().nonnegative('登录次数必须为非负数').default(0).openapi({
    description: '登录次数',
    example: 0
  }),
  loginTime: z.coerce.date().nullable().openapi({
    description: '登录时间',
    example: '2024-01-01T12:00:00Z'
  }),
  loginIp: z.string().max(15, 'IP地址最多15个字符').nullable().optional().openapi({
    description: '登录IP',
    example: '192.168.1.1'
  }),
  lastLoginTime: z.coerce.date().nullable().openapi({
    description: '上次登录时间',
    example: '2024-01-01T12:00:00Z'
  }),
  lastLoginIp: z.string().max(15, 'IP地址最多15个字符').nullable().optional().openapi({
    description: '上次登录IP',
    example: '192.168.1.1'
  }),
  state: z.number().int().min(1).max(2).default(2).openapi({
    description: '状态 1启用 2禁用',
    example: 1
  }),
  createdAt: z.coerce.date().openapi({
    description: '创建时间',
    example: '2024-01-01T12:00:00Z'
  }),
  updatedAt: z.coerce.date().openapi({
    description: '更新时间',
    example: '2024-01-01T12:00:00Z'
  }),
  createdBy: z.number().int().positive().nullable().openapi({
    description: '创建用户ID',
    example: 1
  }),
  updatedBy: z.number().int().positive().nullable().openapi({
    description: '更新用户ID',
    example: 1
  })
});

export const CreateSupplierDto = z.object({
  name: z.string().min(1, '供货商名称不能为空').max(255, '供货商名称最多255个字符').nullable().optional().openapi({
    description: '供货商名称',
    example: '供应商A'
  }),
  username: z.string().min(1, '用户名不能为空').max(20, '用户名最多20个字符').openapi({
    description: '用户名',
    example: 'supplier001'
  }),
  password: z.string().min(6, '密码至少6位').max(255, '密码最多255位').openapi({
    description: '密码',
    example: 'password123'
  }),
  phone: z.string().regex(/^1[3-9]\d{9}$/, '请输入正确的手机号').nullable().optional().openapi({
    description: '手机号码',
    example: '13800138000'
  }),
  realname: z.string().max(20, '姓名最多20个字符').nullable().optional().openapi({
    description: '姓名',
    example: '张三'
  }),
  state: z.number().int().min(1).max(2).default(2).openapi({
    description: '状态 1启用 2禁用',
    example: 1
  })
});

export const UpdateSupplierDto = z.object({
  name: z.string().min(1, '供货商名称不能为空').max(255, '供货商名称最多255个字符').nullable().optional().openapi({
    description: '供货商名称',
    example: '供应商A'
  }),
  username: z.string().min(1, '用户名不能为空').max(20, '用户名最多20个字符').optional().openapi({
    description: '用户名',
    example: 'supplier001'
  }),
  password: z.string().min(6, '密码至少6位').max(255, '密码最多255位').optional().openapi({
    description: '密码',
    example: 'password123'
  }),
  phone: z.string().regex(/^1[3-9]\d{9}$/, '请输入正确的手机号').nullable().optional().openapi({
    description: '手机号码',
    example: '13800138000'
  }),
  realname: z.string().max(20, '姓名最多20个字符').nullable().optional().openapi({
    description: '姓名',
    example: '张三'
  }),
  state: z.number().int().min(1).max(2).optional().openapi({
    description: '状态 1启用 2禁用',
    example: 1
  })
});