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

@Entity('series')
export class Series {
  @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({ type: 'float', nullable: true })
  rating: number | null;

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

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

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

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

  @OneToMany(() => Season, (season) => season.series, { cascade: true })
  seasons: Season[];
}
