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

export const UserMerchantSchemaMt = z.object({
  tenantId: z.number().int().positive().openapi({ description: '租户ID' }),
  id: z.number().int().positive().openapi({ description: '商户ID' }),
  name: z.union([z.string().min(1, '商户名称不能为空').max(255, '商户名称最多255个字符'), z.null()]).openapi({
    description: '商户名称',
    example: '商户A'
  }),
  username: z.string().min(1, '用户名不能为空').max(20, '用户名最多20个字符').openapi({
    description: '用户名',
    example: 'merchant001'
  }),
  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.number().int().nonnegative('登录时间必须为非负数').default(0).openapi({
    description: '登录时间',
    example: 0
  }),
  loginIp: z.string().max(15, 'IP地址最多15个字符').nullable().optional().openapi({
    description: '登录IP',
    example: '192.168.1.1'
  }),
  lastLoginTime: z.number().int().nonnegative('上次登录时间必须为非负数').default(0).openapi({
    description: '上次登录时间',
    example: 0
  }),
  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
  }),
  rsaPublicKey: z.string().max(2000, '公钥最多2000个字符').nullable().optional().openapi({
    description: '公钥',
    example: '-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA...\n-----END PUBLIC KEY-----'
  }),
  aesKey: z.string().max(32, 'aes秘钥最多32个字符').nullable().optional().openapi({
    description: 'aes秘钥',
    example: 'a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6'
  }),
  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().optional().openapi({
    description: '创建用户ID',
    example: 1
  }),
  updatedBy: z.number().int().positive().nullable().optional().openapi({
    description: '更新用户ID',
    example: 1
  })
});

export const UserCreateMerchantDtoMt = z.object({
  tenantId: z.number().int().positive().optional().openapi({ description: '租户ID' }),
  name: z.union([z.string().min(1, '商户名称不能为空').max(255, '商户名称最多255个字符'), z.null()]).openapi({
    description: '商户名称',
    example: '商户A'
  }),
  username: z.string().min(1, '用户名不能为空').max(20, '用户名最多20个字符').openapi({
    description: '用户名',
    example: 'merchant001'
  }),
  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
  }),
  rsaPublicKey: z.string().max(2000, '公钥最多2000个字符').nullable().optional().openapi({
    description: '公钥',
    example: '-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA...\n-----END PUBLIC KEY-----'
  }),
  aesKey: z.string().max(32, 'aes秘钥最多32个字符').nullable().optional().openapi({
    description: 'aes秘钥',
    example: 'a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6'
  })
});

export const UserUpdateMerchantDtoMt = z.object({
  tenantId: z.number().int().positive().optional().openapi({ description: '租户ID' }),
  name: z.union([z.string().min(1, '商户名称不能为空').max(255, '商户名称最多255个字符'), z.null()]).optional().openapi({
    description: '商户名称',
    example: '商户A'
  }),
  username: z.string().min(1, '用户名不能为空').max(20, '用户名最多20个字符').optional().openapi({
    description: '用户名',
    example: 'merchant001'
  }),
  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
  }),
  rsaPublicKey: z.string().max(2000, '公钥最多2000个字符').nullable().optional().openapi({
    description: '公钥',
    example: '-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA...\n-----END PUBLIC KEY-----'
  }),
  aesKey: z.string().max(32, 'aes秘钥最多32个字符').nullable().optional().openapi({
    description: 'aes秘钥',
    example: 'a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6'
  })
});