import {
  Column,
  Entity,
  OneToMany,
  OneToOne,
  PrimaryGeneratedColumn,
} from 'typeorm';
import { Timestamp } from './timestamp';
import { Bid } from './bid.entity';
import { Exclude } from 'class-transformer';
import { ScrapConfig } from '@/modules/scraps/entities/scrap-config.entity';

@Entity('web_bids')
export class WebBid extends Timestamp {
  @PrimaryGeneratedColumn('increment')
  id: number;

  @Column({ unique: true })
  origin_url: string;

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

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

  @Column({ default: 300 })
  arrival_offset_seconds: number;

  @Column({ default: 600 })
  early_tracking_seconds: number;

  @Column({ default: null })
  snapshot_at: Date | null;

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

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

  @OneToMany(() => Bid, (bid) => bid.web_bid, {
    cascade: true,
  })
  children: Bid[];

  @OneToOne(() => ScrapConfig, (scrap) => scrap.web_bid)
  scrap_config: ScrapConfig;
}
