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

export enum NotificationChannel { PUSH = 'push', SMS = 'sms', EMAIL = 'email', IN_APP = 'in_app' }
export enum NotificationStatus { PENDING = 'pending', SENT = 'sent', FAILED = 'failed', READ = 'read' }

@Entity('notifications')
@Index('idx_notifications_user', ['userId'])
export class Notification {
  @PrimaryGeneratedColumn('uuid') id: string;
  @Column({ name: 'user_id', type: 'uuid' }) userId: string;
  @Column({ type: 'varchar', length: 20 }) channel: NotificationChannel;
  @Column({ type: 'varchar', length: 200 }) title: string;
  @Column({ type: 'text' }) body: string;
  @Column({ type: 'jsonb', nullable: true }) data: Record<string, any> | null;
  @Column({ type: 'varchar', length: 20, default: 'pending' }) status: NotificationStatus;
  @Column({ name: 'sent_at', type: 'timestamptz', nullable: true }) sentAt: Date | null;
  @Column({ name: 'read_at', type: 'timestamptz', nullable: true }) readAt: Date | null;
  @CreateDateColumn({ name: 'created_at', type: 'timestamptz' }) createdAt: Date;
}
