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

export const TenantSchema = z.object({
  id: z.number().int().positive().openapi({ description: '租户ID' }),
  name: z.string().min(1, '租户名称不能为空').max(255, '租户名称最多255个字符').nullable().openapi({
    description: '租户名称',
    example: '租户A'
  }),
  code: z.string().min(1, '租户代码不能为空').max(50, '租户代码最多50个字符').openapi({
    description: '租户代码',
    example: 'tenant001'
  }),
  phone: z.string().regex(/^1[3-9]\d{9}$/, '请输入正确的手机号').nullable().optional().openapi({
    description: '联系电话',
    example: '13800138000'
  }),
  contactName: z.string().max(20, '联系人姓名最多20个字符').nullable().optional().openapi({
    description: '联系人姓名',
    example: '李四'
  }),
  status: z.number().int().min(1).max(2).default(1).openapi({
    description: '状态 1启用 2禁用',
    example: 1
  }),
  config: z.record(z.any()).nullable().optional().openapi({
    description: '租户配置',
    example: { theme: 'dark', language: 'zh-CN' }
  } as const),
  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().openapi({
    description: '创建用户ID',
    example: 1
  }),
  updatedBy: z.number().int().positive().nullable().openapi({
    description: '更新用户ID',
    example: 1
  })
});

export const CreateTenantDto = z.object({
  name: z.string().min(1, '租户名称不能为空').max(255, '租户名称最多255个字符').nullable().optional().openapi({
    description: '租户名称',
    example: '租户A'
  }),
  code: z.string().min(1, '租户代码不能为空').max(50, '租户代码最多50个字符').openapi({
    description: '租户代码',
    example: 'tenant001'
  }),
  phone: z.string().regex(/^1[3-9]\d{9}$/, '请输入正确的手机号').nullable().optional().openapi({
    description: '联系电话',
    example: '13800138000'
  }),
  contactName: z.string().max(20, '联系人姓名最多20个字符').nullable().optional().openapi({
    description: '联系人姓名',
    example: '李四'
  }),
  status: z.number().int().min(1).max(2).default(1).openapi({
    description: '状态 1启用 2禁用',
    example: 1
  }),
  config: z.record(z.any()).nullable().optional().openapi({
    description: '租户配置',
    example: { theme: 'dark', language: 'zh-CN' }
  } as const),
  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 UpdateTenantDto = z.object({
  name: z.string().min(1, '租户名称不能为空').max(255, '租户名称最多255个字符').nullable().optional().openapi({
    description: '租户名称',
    example: '租户A'
  }),
  code: z.string().min(1, '租户代码不能为空').max(50, '租户代码最多50个字符').optional().openapi({
    description: '租户代码',
    example: 'tenant001'
  }),
  phone: z.string().regex(/^1[3-9]\d{9}$/, '请输入正确的手机号').nullable().optional().openapi({
    description: '联系电话',
    example: '13800138000'
  }),
  contactName: z.string().max(20, '联系人姓名最多20个字符').nullable().optional().openapi({
    description: '联系人姓名',
    example: '李四'
  }),
  status: z.number().int().min(1).max(2).optional().openapi({
    description: '状态 1启用 2禁用',
    example: 1
  }),
  config: z.record(z.any()).nullable().optional().openapi({
    description: '租户配置',
    example: { theme: 'dark', language: 'zh-CN' }
  } as const),
  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'
  })
});