import { Entity, ManyToMany } from 'typeorm';
import { BaseEntity } from '../base-entity';
import { MultiName, MultiNamed } from './base/multi-named';
import { Book } from './book';
import { Fiction } from './fiction';

@Entity()
export class Character extends MultiNamed(BaseEntity, 'CharacterMultiName') {
  @ManyToMany(() => Book, {
    nullable: false,
    onDelete: 'CASCADE',
    onUpdate: 'CASCADE',
  })
  public books: Promise<Book[]>;

  @ManyToMany(() => Fiction, {
    nullable: true,
    onDelete: 'CASCADE',
    onUpdate: 'CASCADE',
  })
  public fictions: Promise<Fiction[]>;
}

@Entity()
export class CharacterMultiName extends MultiName('Character') {}
