import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn } from 'typeorm';
import { UserEntity } from '../users/user.entity';

@Entity('submission_records')
export class SubmissionRecords {
  @PrimaryGeneratedColumn({ unsigned: true })
  id!: number;

  @Column({ name: 'classroom_no', type: 'varchar', length: 255, nullable: true, comment: '教室号' })
  classroomNo!: string | null;

  @Column({ name: 'user_id', type: 'int', unsigned: true, nullable: true, comment: '用户id' })
  userId!: number | null;

  // 单向关联定义
  @ManyToOne(() => UserEntity, { nullable: true })
  @JoinColumn({ name: 'user_id' })
  user!: UserEntity | null;


  @Column({ name: 'score', type: 'decimal', precision: 10, scale: 2, nullable: true, comment: '成绩' })
  score!: number | null;

  @Column({ name: 'code', type: 'varchar', length: 255, nullable: true, comment: '代码' })
  code!: string | null;

  @Column({ name: 'training_date', type: 'timestamp', nullable: true, comment: '训练日期' })
  trainingDate!: Date | null;

  @Column({ name: 'mark', type: 'varchar', length: 255, nullable: true, comment: '标记' })
  mark!: string | null;

  @Column({ name: 'status', type: 'int', nullable: true, comment: '状态' })
  status!: number | null;

  @Column({ name: 'holding_stock', type: 'varchar', length: 255, nullable: true, comment: '持股' })
  holdingStock!: string | null;

  @Column({ name: 'holding_cash', type: 'varchar', length: 255, nullable: true, comment: '持币' })
  holdingCash!: string | null;

  @Column({ name: 'price', type: 'decimal', precision: 10, scale: 2, nullable: true, comment: '价格' })
  price!: number | null;

  @Column({ name: 'profit_amount', type: 'decimal', precision: 10, scale: 2, nullable: true, comment: '收益金额' })
  profitAmount!: number | null;

  @Column({ name: 'profit_percent', type: 'decimal', precision: 10, scale: 2, nullable: true, comment: '收益率' })
  profitPercent!: number | null;

  @Column({ name: 'total_profit_amount', type: 'decimal', precision: 10, scale: 2, nullable: true, comment: '累计收益金额' })
  totalProfitAmount!: number | null;

  @Column({ name: 'total_profit_percent', type: 'decimal', precision: 10, scale: 2, nullable: true, comment: '累计收益率' })
  totalProfitPercent!: number | null;

  @Column({ name: 'created_at', type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' })
  createdAt!: Date;

  @Column({ name: 'updated_at', type: 'timestamp', default: () => 'CURRENT_TIMESTAMP', onUpdate: 'CURRENT_TIMESTAMP' })
  updatedAt!: Date;
}