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

export class ScsUser {
  [PrimaryKeyProp]?: 'Id';
  Id!: IType<number, bigint>;
  RoleType!: number;
  No?: string;
  SchoolUserNo?: string;
  Name?: string;
  Pwd?: string;
  Avatar?: string;
  Sex!: number;
  Phone?: string;
  Photo?: string;
  Motto?: string;
  Remark?: string;
  Enabled!: unknown;
  Revision!: number;
  CreatedBy?: IType<number, bigint>;
  CreatedTime!: Date;
  UpdatedBy?: IType<number, bigint>;
  UpdatedTime?: Date;
  IsDeleted!: unknown;
  DotMatrixOnlineStatus: number & Opt = 0;
  DotMatrixOnlineTime?: Date;
  LastLoginTime?: Date;
  ExpireTime!: Date & Opt;
}

export const ScsUserSchema = defineEntity({
  class: ScsUser,
  properties: {
    Id: p.bigint().primary().name('Id').columnType('bigint').unsigned(false).autoincrement(false).comment('主键Id'),
    RoleType: p.integer().name('RoleType').comment('角色（学生 普通教师 名师）'),
    No: p.string().name('No').length(30).nullable().comment('编号').unique('idx_SCS_User_02'),
    SchoolUserNo: p.string().name('SchoolUserNo').nullable().comment('学校内的的工号（学号）'),
    Name: p.string().name('Name').length(30).nullable().comment('用户名').index('idx_SCS_User_03'),
    Pwd: p.string().name('Pwd').length(20).nullable().comment('用户密码'),
    Avatar: p.string().name('Avatar').length(500).nullable().comment('头像'),
    Sex: p.integer().name('Sex').comment('性别'),
    Phone: p.string().name('Phone').length(20).nullable().comment('电话').index('idx_SCS_User_01'),
    Photo: p.string().name('Photo').nullable().comment('照片'),
    Motto: p.string().name('Motto').length(100).nullable().comment('座右铭'),
    Remark: p.string().name('Remark').length(2000).nullable().comment('备注'),
    Enabled: p.array().name('Enabled').comment('启用'),
    Revision: p.integer().name('Revision').comment('乐观锁'),
    CreatedBy: p.bigint().name('CreatedBy').columnType('bigint').nullable().comment('创建者用户Id'),
    CreatedTime: p.datetime().name('CreatedTime').length(3).comment('创建时间'),
    UpdatedBy: p.bigint().name('UpdatedBy').columnType('bigint').nullable().comment('修改者用户Id'),
    UpdatedTime: p.datetime().name('UpdatedTime').length(3).nullable().comment('修改时间'),
    IsDeleted: p.array().name('IsDeleted').comment('是否删除'),
    DotMatrixOnlineStatus: p.integer().name('DotMatrixOnlineStatus').comment('点阵在线状态'),
    DotMatrixOnlineTime: p.datetime().name('DotMatrixOnlineTime').length(3).nullable().comment('点阵在线时间'),
    LastLoginTime: p.datetime().name('LastLoginTime').length(3).nullable().comment('最后登录时间'),
    ExpireTime: p.datetime().name('ExpireTime').length(3).comment('账号过期时间').defaultRaw(`9999-12-31 23:59:59.999`),
  },
});
