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

// 教室状态枚举
export enum ClassroomStatus {
  CLOSED = 0,  // 关闭
  OPEN = 1     // 开放
}

// 教室状态中文映射
export const ClassroomStatusNameMap: Record<ClassroomStatus, string> = {
  [ClassroomStatus.CLOSED]: '关闭',
  [ClassroomStatus.OPEN]: '开放'
};

// 实体完整Schema
export const ClassroomDataSchema = z.object({
  id: z.number().int('必须是整数').positive('必须是正整数').openapi({
    description: '教室数据ID',
    example: 1
  }),
  classroomNo: z.string().max(255, '教室号最多255个字符').nullable().openapi({
    description: '教室号',
    example: 'A101'
  }),
  trainingDate: z.coerce.date<Date>().nullable().openapi({
    description: '训练日期',
    example: '2024-01-15T08:00:00Z'
  }),
  holdingStock: z.string().max(255, '持股信息最多255个字符').nullable().openapi({
    description: '持股',
    example: 'AAPL,100股'
  }),
  holdingCash: z.string().max(255, '持币信息最多255个字符').nullable().openapi({
    description: '持币',
    example: 'USD,5000'
  }),
  price: z.string().max(255, '价格信息最多255个字符').nullable().openapi({
    description: '价格',
    example: '150.25'
  }),
  code: z.string().max(255, '代码最多255个字符').nullable().openapi({
    description: '代码',
    example: 'AAPL'
  }),
  status: z.enum(ClassroomStatus).nullable().openapi({
    description: '状态 (0关闭 1开放)',
    example: ClassroomStatus.OPEN
  }),
  spare: z.string().max(255, '备用信息最多255个字符').nullable().openapi({
    description: '备用',
    example: '备用信息'
  }),
  createdBy: z.coerce.number<number>().int('创建用户ID必须是整数').positive('创建用户ID必须是正整数').nullable().openapi({
    description: '创建用户ID',
    example: 1
  }),
  updatedBy: z.coerce.number<number>().int('更新用户ID必须是整数').positive('更新用户ID必须是正整数').nullable().openapi({
    description: '更新用户ID',
    example: 1
  }),
  createdAt: z.coerce.date<Date>().openapi({
    description: '创建时间',
    example: '2024-01-15T08:00:00Z'
  }),
  updatedAt: z.coerce.date<Date>().openapi({
    description: '更新时间',
    example: '2024-01-15T08:00:00Z'
  })
});

// 创建教室数据DTO
export const CreateClassroomDataDto = z.object({
  classroomNo: z.string().max(255, '教室号最多255个字符').nullable().optional().openapi({
    description: '教室号',
    example: 'A101'
  }),
  trainingDate: z.coerce.date<Date>().nullable().optional().openapi({
    description: '训练日期',
    example: '2024-01-15T08:00:00Z'
  }),
  holdingStock: z.string().max(255, '持股信息最多255个字符').nullable().optional().openapi({
    description: '持股',
    example: 'AAPL,100股'
  }),
  holdingCash: z.string().max(255, '持币信息最多255个字符').nullable().optional().openapi({
    description: '持币',
    example: 'USD,5000'
  }),
  price: z.string().max(255, '价格信息最多255个字符').nullable().optional().openapi({
    description: '价格',
    example: '150.25'
  }),
  code: z.string().max(255, '代码最多255个字符').nullable().optional().openapi({
    description: '代码',
    example: 'AAPL'
  }),
  status: z.enum(ClassroomStatus).nullable().optional().openapi({
    description: '状态 (0关闭 1开放)',
    example: ClassroomStatus.OPEN
  }),
  spare: z.string().max(255, '备用信息最多255个字符').nullable().optional().openapi({
    description: '备用',
    example: '备用信息'
  })
});

// 更新教室数据DTO
export const UpdateClassroomDataDto = z.object({
  classroomNo: z.string().max(255, '教室号最多255个字符').nullable().optional().openapi({
    description: '教室号',
    example: 'A101'
  }),
  trainingDate: z.coerce.date<Date>().nullable().optional().openapi({
    description: '训练日期',
    example: '2024-01-15T08:00:00Z'
  }),
  holdingStock: z.string().max(255, '持股信息最多255个字符').nullable().optional().openapi({
    description: '持股',
    example: 'AAPL,100股'
  }),
  holdingCash: z.string().max(255, '持币信息最多255个字符').nullable().optional().openapi({
    description: '持币',
    example: 'USD,5000'
  }),
  price: z.string().max(255, '价格信息最多255个字符').nullable().optional().openapi({
    description: '价格',
    example: '150.25'
  }),
  code: z.string().max(255, '代码最多255个字符').nullable().optional().openapi({
    description: '代码',
    example: 'AAPL'
  }),
  status: z.enum(ClassroomStatus).nullable().optional().openapi({
    description: '状态 (0关闭 1开放)',
    example: ClassroomStatus.OPEN
  }),
  spare: z.string().max(255, '备用信息最多255个字符').nullable().optional().openapi({
    description: '备用',
    example: '备用信息'
  })
});