import { Column, Entity, ManyToMany, ManyToOne } from 'typeorm';
import { BaseEntity } from '../base-entity';
import { Copy } from './copy';
import { Site } from './site';

@Entity()
export class Source extends BaseEntity {
  @Column({
    nullable: false,
    unique: true,
  })
  public uri: string;

  @ManyToOne(
    () => Site,
    (site: Site) => site.sources,
    {
      nullable: false,
      onDelete: 'CASCADE',
      onUpdate: 'CASCADE',
    }
  )
  public site: Promise<Site>;

  @ManyToMany(() => Copy, {
    nullable: false,
    onDelete: 'CASCADE',
    onUpdate: 'CASCADE',
  })
  public copies: Promise<Copy[]>;
}
