import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
} from 'typeorm';
import { NotificationType } from '../enums/notification-type.enum';

@Entity('notifications')
export class Notification {

  @PrimaryGeneratedColumn()
  id: number;

  // Uses enum — only valid types accepted
  // e.g. NotificationType.PROPOSAL_SIGNED
  @Column({
    type: 'enum',
    enum: NotificationType,
  })
  type: NotificationType;

  @Column()
  title: string;

  @Column({ type: 'text' })
  body: string;

  // Role IDs that received this notification
  // e.g. [4, 9] → manager + admin
  @Column({ type: 'simple-array', nullable: true })
  target_role_ids: number[];

  // Personal notifications — engineer user IDs
  // e.g. [42] → only engineer with id 42
  @Column({ type: 'simple-array', nullable: true })
  target_user_ids: number[];

  // ID of the source record
  // e.g. proposal.id = 61, invoice.id = 42
  @Column({ nullable: true })
  reference_id: number;

  // Which module fired this notification
  // e.g. 'PROPOSAL', 'INVOICE', 'EXECUTION'
  @Column({ nullable: true })
  reference_type: string;

  // true → socket emits 'notification:urgent'
  // Frontend shows red alert
  @Column({ default: false })
  is_urgent: boolean;

  // true → socket emits 'notification:action'
  // Frontend shows amber action panel
  @Column({ default: false })
  requires_action: boolean;

  // false = unread (shows in bell badge count)
  // true  = user has seen it
  @Column({ default: false })
  is_read: boolean;

  // Which user marked it read
  @Column({ nullable: true })
  read_by_user_id: number;

  @CreateDateColumn()
  created_at: Date;
}