import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  ManyToMany,
  JoinTable,
} from 'typeorm';
import { Category } from '../../categories/entities/category.entity';

@Entity('movies')
export class Movie {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column()
  title: string;

  @Column({ type: 'text', nullable: true })
  synopsis: string | null;

  @Column({ nullable: true })
  posterUrl: string | null;

  @Column({ nullable: true })
  backdropUrl: string | null;

  @Column()
  streamUrl: string;

  @Column({ nullable: true })
  durationMin: number | null;

  @Column({ nullable: true })
  year: number | null;

  @Column({ type: 'float', nullable: true })
  rating: number | null;

  @Column({ default: true })
  isActive: boolean;

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

  @ManyToMany(() => Category, { eager: true })
  @JoinTable({
    name: 'movie_categories',
    joinColumn: { name: 'movieId', referencedColumnName: 'id' },
    inverseJoinColumn: { name: 'categoryId', referencedColumnName: 'id' },
  })
  categories: Category[];
}
