import {
  Column,
  Entity,
  JoinColumn,
  ManyToOne,
  PrimaryGeneratedColumn,
  Unique,
} from 'typeorm';
import { ScrapConfig } from './scrap-config.entity';
import { Timestamp } from './timestamp';

@Entity('scrap-items')
@Unique(['model', 'scrap_config_id'])
export class ScrapItem extends Timestamp {
  @PrimaryGeneratedColumn('increment')
  id: number;

  @Column()
  name: string;

  @Column()
  url: string;

  @Column()
  model: string;

  @Column({ nullable: true, default: null })
  image_url: string | null;

  @Column({ nullable: true, default: null })
  keyword: string;

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

  @Column()
  scrap_config_id: number;

  @ManyToOne(() => ScrapConfig, (web) => web.scrap_items, {
    onDelete: 'CASCADE',
  })
  @JoinColumn({ name: 'scrap_config_id' })
  scrap_config: ScrapConfig;
}
