import {
  Entity, Column, PrimaryGeneratedColumn, OneToOne, JoinColumn, OneToMany, CreateDateColumn, UpdateDateColumn, DeleteDateColumn, BeforeInsert, BeforeUpdate,
  ManyToOne,
  RelationId
} from 'typeorm';
import { Exclude, Expose } from 'class-transformer';
import { Users } from './users.entity';

export enum Type {
  NOTIFICATION = 'notification',
  SYSTEM = 'system',
  GUEST = 'guest',
  USER = 'user',
  CHASE_UP = 'chase_up',
}

export enum RedirectType {
  CAMPAIGN_MANAGEMENT = 'campaign_management',
  INVITED = 'invited',
  JOB_CLOSED = 'job_closed',
  JOB_INPROGRESS = 'job_inprogress',
  APPLIED = 'applied',
  BRAND_LIST = 'brand_details',
  INFLUENCER_LIST = 'influencer_details',
  CAMPAIGN_LIST = 'campaign_details',
  AI_REPORT = 'ai_report',
  DISPUTE = 'dispute_details',
  PAYMENT_LIST = 'payment_list',
  BRAND_SUBSCRIPTION = 'brand_subscription',
}

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

  @ManyToOne(() => Users, user => user.id, { nullable: true })
  @JoinColumn({ name: "sender_id" })
  sender: Users;

  @RelationId((notification: Notifications) => notification.sender)
  sender_id: string;

  @ManyToOne(() => Users, user => user.id, { nullable: true })
  @JoinColumn({ name: "receiver_id" })
  receiver: Users;

  @RelationId((notification: Notifications) => notification.receiver)
  receiver_id: string;

  @Column({ type: 'text', nullable: true })
  description: string;

  @Column({
    type: 'enum',
    enum: Type,
    default: Type.NOTIFICATION,
  })
  type: string;

  @Column({ nullable: true })
  redirect_type: string;

  @Column({ nullable: true })
  redirect_id: string;

  @Column({ nullable: true })
  redirect_slug: string;

  @Column({ type: 'jsonb', nullable: true })
  metadata: Record<string, any>;

  @Column({ type: 'boolean', default: false })
  is_read: boolean

  @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;

}
