import { z } from '@hono/zod-openapi';
import { UserSchema } from '../users/user.schema';

// 提交记录Schema定义
export const SubmissionRecordsSchema = z.object({
  id: z.number().int('必须是整数').positive('必须是正整数').openapi({
    description: '提交记录ID',
    example: 1
  }),
  classroomNo: z.string().max(255, '教室号最多255个字符').nullable().openapi({
    description: '教室号',
    example: 'A101'
  }),
  userId: z.coerce.number<number>().int('用户ID必须是整数').positive('用户ID必须是正整数').nullable().openapi({
    description: '用户ID',
    example: 1
  }),
  user: UserSchema.omit({ password: true }).nullable().optional().openapi({
    description: '用户信息'
  }),
  score: z.coerce.number<number>().multipleOf(0.01, '成绩最多保留两位小数').nullable().openapi({
    description: '成绩',
    example: 95.5
  }),
  code: z.string().max(255, '代码最多255个字符').nullable().openapi({
    description: '代码',
    example: '600000.SH'
  }),
  trainingDate: z.coerce.date<Date>().nullable().openapi({
    description: '训练日期',
    example: '2024-01-15T08:00:00Z'
  }),
  mark: z.string().max(255, '标记最多255个字符').nullable().openapi({
    description: '标记',
    example: '优秀'
  }),
  status: z.coerce.number<number>().int('状态必须是整数').nullable().openapi({
    description: '状态',
    example: 1
  }),
  holdingStock: z.string().max(255, '持股最多255个字符').nullable().openapi({
    description: '持股',
    example: '600000.SH'
  }),
  holdingCash: z.string().max(255, '持币最多255个字符').nullable().openapi({
    description: '持币',
    example: '10000.00'
  }),
  price: z.coerce.number<number>().multipleOf(0.01, '价格最多保留两位小数').nullable().openapi({
    description: '价格',
    example: 10.5
  }),
  profitAmount: z.coerce.number<number>().multipleOf(0.01, '收益金额最多保留两位小数').nullable().openapi({
    description: '收益金额',
    example: 500.25
  }),
  profitPercent: z.coerce.number<number>().multipleOf(0.01, '收益率最多保留两位小数').nullable().openapi({
    description: '收益率',
    example: 5.25
  }),
  totalProfitAmount: z.coerce.number<number>().multipleOf(0.01, '累计收益金额最多保留两位小数').nullable().openapi({
    description: '累计收益金额',
    example: 2500.75
  }),
  totalProfitPercent: z.coerce.number<number>().multipleOf(0.01, '累计收益率最多保留两位小数').nullable().openapi({
    description: '累计收益率',
    example: 12.5
  }),
  createdAt: z.coerce.date<Date>().openapi({
    description: '创建时间',
    example: '2024-01-15T08:00:00Z'
  }),
  updatedAt: z.coerce.date<Date>().openapi({
    description: '更新时间',
    example: '2024-01-15T08:30:00Z'
  })
});

// 创建提交记录DTO
export const CreateSubmissionRecordsDto = z.object({
  classroomNo: z.string().max(255, '教室号最多255个字符').nullable().optional().openapi({
    description: '教室号',
    example: 'A101'
  }),
  userId: z.coerce.number<number>().int('用户ID必须是整数').positive('用户ID必须是正整数').nullable().optional().openapi({
    description: '用户ID',
    example: 1
  }),
  score: z.coerce.number<number>().multipleOf(0.01, '成绩最多保留两位小数').nullable().optional().openapi({
    description: '成绩',
    example: 95.5
  }),
  code: z.string().max(255, '代码最多255个字符').nullable().optional().openapi({
    description: '代码',
    example: '600000.SH'
  }),
  trainingDate: z.coerce.date<Date>().nullable().optional().openapi({
    description: '训练日期',
    example: '2024-01-15T08:00:00Z'
  }),
  mark: z.string().max(255, '标记最多255个字符').nullable().optional().openapi({
    description: '标记',
    example: '优秀'
  }),
  status: z.coerce.number<number>().int('状态必须是整数').nullable().optional().openapi({
    description: '状态',
    example: 1
  }),
  holdingStock: z.string().max(255, '持股最多255个字符').nullable().optional().openapi({
    description: '持股',
    example: '600000.SH'
  }),
  holdingCash: z.string().max(255, '持币最多255个字符').nullable().optional().openapi({
    description: '持币',
    example: '10000.00'
  }),
  price: z.coerce.number<number>().multipleOf(0.01, '价格最多保留两位小数').nullable().optional().openapi({
    description: '价格',
    example: 10.5
  }),
  profitAmount: z.coerce.number<number>().multipleOf(0.01, '收益金额最多保留两位小数').nullable().optional().openapi({
    description: '收益金额',
    example: 500.25
  }),
  profitPercent: z.coerce.number<number>().multipleOf(0.01, '收益率最多保留两位小数').nullable().optional().openapi({
    description: '收益率',
    example: 5.25
  }),
  totalProfitAmount: z.coerce.number<number>().multipleOf(0.01, '累计收益金额最多保留两位小数').nullable().optional().openapi({
    description: '累计收益金额',
    example: 2500.75
  }),
  totalProfitPercent: z.coerce.number<number>().multipleOf(0.01, '累计收益率最多保留两位小数').nullable().optional().openapi({
    description: '累计收益率',
    example: 12.5
  })
});

// 更新提交记录DTO
export const UpdateSubmissionRecordsDto = z.object({
  classroomNo: z.string().max(255, '教室号最多255个字符').nullable().optional().openapi({
    description: '教室号',
    example: 'A101'
  }),
  userId: z.coerce.number<number>().int('用户ID必须是整数').positive('用户ID必须是正整数').nullable().optional().openapi({
    description: '用户ID',
    example: 1
  }),
  score: z.coerce.number<number>().multipleOf(0.01, '成绩最多保留两位小数').nullable().optional().openapi({
    description: '成绩',
    example: 95.5
  }),
  code: z.string().max(255, '代码最多255个字符').nullable().optional().openapi({
    description: '代码',
    example: '600000.SH'
  }),
  trainingDate: z.coerce.date<Date>().nullable().optional().openapi({
    description: '训练日期',
    example: '2024-01-15T08:00:00Z'
  }),
  mark: z.string().max(255, '标记最多255个字符').nullable().optional().openapi({
    description: '标记',
    example: '优秀'
  }),
  status: z.coerce.number<number>().int('状态必须是整数').nullable().optional().openapi({
    description: '状态',
    example: 1
  }),
  holdingStock: z.string().max(255, '持股最多255个字符').nullable().optional().openapi({
    description: '持股',
    example: '600000.SH'
  }),
  holdingCash: z.string().max(255, '持币最多255个字符').nullable().optional().openapi({
    description: '持币',
    example: '10000.00'
  }),
  price: z.coerce.number<number>().multipleOf(0.01, '价格最多保留两位小数').nullable().optional().openapi({
    description: '价格',
    example: 10.5
  }),
  profitAmount: z.coerce.number<number>().multipleOf(0.01, '收益金额最多保留两位小数').nullable().optional().openapi({
    description: '收益金额',
    example: 500.25
  }),
  profitPercent: z.coerce.number<number>().multipleOf(0.01, '收益率最多保留两位小数').nullable().optional().openapi({
    description: '收益率',
    example: 5.25
  }),
  totalProfitAmount: z.coerce.number<number>().multipleOf(0.01, '累计收益金额最多保留两位小数').nullable().optional().openapi({
    description: '累计收益金额',
    example: 2500.75
  }),
  totalProfitPercent: z.coerce.number<number>().multipleOf(0.01, '累计收益率最多保留两位小数').nullable().optional().openapi({
    description: '累计收益率',
    example: 12.5
  })
});