import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  ManyToOne,
  JoinColumn,
  Unique,
} from 'typeorm';
import { ContentType } from '../../common/enums';
import { User } from '../../users/entities/user.entity';

@Entity('favorites')
@Unique(['userId', 'contentId', 'contentType'])
export class Favorite {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column()
  userId: string;

  @ManyToOne(() => User, (user) => user.favorites, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'userId' })
  user: User;

  @Column('uuid')
  contentId: string;

  @Column({ type: 'enum', enum: ContentType })
  contentType: ContentType;

  @CreateDateColumn({ type: 'timestamptz' })
  createdAt: Date;
}
