import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn } from 'typeorm';

export enum NoticeType {
  SYSTEM = 'system',
  USER = 'user',
  BROADCAST = 'broadcast',
}

export enum NoticeStatus {
  PENDING = 'pending',
  SENT = 'sent',
  READ = 'read',
  FAILED = 'failed',
}

@Entity('notices')
export class Notice {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  title: string;

  @Column('text')
  content: string;

  @Column({
    type: 'enum',
    enum: NoticeType,
    default: NoticeType.SYSTEM,
  })
  type: NoticeType;

  @Column({
    type: 'enum',
    enum: NoticeStatus,
    default: NoticeStatus.PENDING,
  })
  status: NoticeStatus;

  @Column({ nullable: true })
  userId: number; // 接收者ID，null表示广播通知

  @Column({ nullable: true })
  senderId: number; // 发送者ID

  @Column({ type: 'datetime', nullable: true })
  scheduledAt: Date; // 计划发送时间

  @Column({ type: 'datetime', nullable: true })
  sentAt: Date; // 实际发送时间

  @Column({ type: 'datetime', nullable: true })
  readAt: Date; // 阅读时间

  @Column({ type: 'json', nullable: true })
  metadata: Record<string, any>; // 额外数据

  @CreateDateColumn()
  createdAt: Date;

  @UpdateDateColumn()
  updatedAt: Date;
}