import { type Opt, PrimaryKeyProp, defineEntity, p } from '@mikro-orm/core';

export class IcrHomework {
  [PrimaryKeyProp]?: 'Id';
  Id!: bigint;
  Name?: string;
  SubjectIds?: unknown;
  BookId!: bigint;
  StudentGroupId!: bigint;
  StartTime!: Date;
  EndTime!: Date;
  Status!: number;
  Type!: number;
  PdfUrl?: string;
  TriggerTime?: Date;
  Revision!: number;
  CreatedBy?: bigint;
  CreatedTime!: Date;
  UpdatedBy?: bigint;
  UpdatedTime?: Date;
  IsDeleted!: unknown;
  ReviewIds?: unknown;
  DraftTemplateId?: bigint;
  ExamRoomId!: bigint & Opt;
  TutorRoomId?: bigint;
  MeetingStatus: number & Opt = 0;
  ReviewTime?: Date;
  ClassRoomCourseId?: bigint;
}

export const IcrHomeworkSchema = defineEntity({
  class: IcrHomework,
  comment: '作业',
  properties: {
    Id: p.bigint().primary().name('Id').unsigned(false).autoincrement(false).comment('主键Id'),
    Name: p.string().name('Name').nullable().comment('名称'),
    SubjectIds: p.array().name('SubjectIds').length(4294967295).nullable().comment('学科Ids'),
    BookId: p.bigint().name('BookId').comment('引用书籍Id').index('idx_ICR_Homework_01'),
    StudentGroupId: p.bigint().name('StudentGroupId').comment('引用学生模板Id').index('idx_ICR_Homework_02'),
    StartTime: p.datetime().name('StartTime').length(3).comment('发布时间'),
    EndTime: p.datetime().name('EndTime').length(3).comment('结束时间'),
    Status: p.integer().name('Status').comment('状态'),
    Type: p.integer().name('Type').comment('作业类型'),
    PdfUrl: p.string().name('PdfUrl').nullable().comment('pdf预览地址'),
    TriggerTime: p.datetime().name('TriggerTime').length(3).nullable().comment('触发时间'),
    Revision: p.integer().name('Revision').comment('乐观锁'),
    CreatedBy: p.bigint().name('CreatedBy').nullable().comment('创建者用户Id'),
    CreatedTime: p.datetime().name('CreatedTime').length(3).comment('创建时间'),
    UpdatedBy: p.bigint().name('UpdatedBy').nullable().comment('修改者用户Id'),
    UpdatedTime: p.datetime().name('UpdatedTime').length(3).nullable().comment('修改时间'),
    IsDeleted: p.array().name('IsDeleted').comment('是否删除'),
    ReviewIds: p.array().name('ReviewIds').length(4294967295).nullable().comment('批阅人ids'),
    DraftTemplateId: p.bigint().name('DraftTemplateId').nullable().comment('草稿纸模板id'),
    ExamRoomId: p.bigint().name('ExamRoomId').comment('考场Id').defaultRaw(`0`),
    TutorRoomId: p.bigint().name('TutorRoomId').nullable().comment('辅导室Id'),
    MeetingStatus: p.integer().name('MeetingStatus').comment('会议状态(0-待开课 1-上课中 -1-结束)'),
    ReviewTime: p.datetime().name('ReviewTime').length(3).nullable().comment('批阅时间'),
    ClassRoomCourseId: p.bigint().name('ClassRoomCourseId').nullable().comment('互动课程Id'),
  },
});
