import {
  Entity,
  Column,
  PrimaryGeneratedColumn,
  ManyToOne,
  JoinColumn,
  CreateDateColumn,
  UpdateDateColumn,
  DeleteDateColumn,
  Unique
} from 'typeorm';
import { Exclude } from 'class-transformer';
import { Users } from './users.entity';

export enum NotificationChannel {
  WHATSAPP_NOTIFICATION = 'whatsapp_notification',

}
// EMAIL_NOTIFICATION = 'email_notification',
//   NOTIFICATION = 'notification'
export enum DEFAULT_ENABLED_EVENT_TYPES {
  CLOSED = "closed",
  COMPLETION_REQUEST = "completion_request",
  DRAFT_AVAILABLE = "draft_available",
  DRAFTING_DELIVERABLES = "drafting_deliverables",
  POSTING_DELIVERABLES = "posting_deliverables",
  QUOTATION_AVAILABLE = "quotation_available",
  UNCONNTACTED = "uncontacted",
  WAITING_FOR_QUOTATIONS = "waiting_for_quotations",
  ARCHIVED = "archived"
}


@Entity({ name: 'user_notification_preferences' })
export class UserNotificationPreferences {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @ManyToOne(() => Users, (user) => user.notificationPreferences, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'user_id' })
  user: Users;

  @Column({ type: 'enum', enum: NotificationChannel })
  channel: NotificationChannel;

  @Column({ type: 'boolean', default: true })
  is_enabled: boolean;


  @Column({ type: 'jsonb', default: [] })
  enabled_types: string[];

  @Exclude()
  @CreateDateColumn({
    type: 'timestamp',
    precision: 0,
    default: () => 'CURRENT_TIMESTAMP'
  })
  created_at: Date;

  @Exclude()
  @UpdateDateColumn({
    type: 'timestamp',
    precision: 0,
    default: () => 'CURRENT_TIMESTAMP',
    onUpdate: 'CURRENT_TIMESTAMP'
  })
  updated_at: Date;

  @Exclude()
  @DeleteDateColumn({ type: 'timestamp', nullable: true, precision: 0 })
  deleted_at: Date;
}

