import {
  Column, CreateDateColumn, DeleteDateColumn, Entity,
  ManyToOne, JoinColumn, PrimaryGeneratedColumn, UpdateDateColumn,
} from 'typeorm';
import { LoanAccount } from './loan-account.entity';

@Entity('auctions')
export class Auction {
  @PrimaryGeneratedColumn('uuid') id: string;

  @Column({ type: 'varchar', length: 30, unique: true }) auctionNumber: string;

  @Column({ type: 'varchar', nullable: true }) loanAccountId: string | null;
  @ManyToOne(() => LoanAccount, { nullable: true, onDelete: 'SET NULL' })
  @JoinColumn({ name: 'loanAccountId' })
  loanAccount: LoanAccount | null;

  @Column({ type: 'varchar', length: 100, nullable: true }) collateralType: string | null;
  @Column({ type: 'text', nullable: true }) collateralDescription: string | null;
  @Column({ type: 'decimal', precision: 15, scale: 2, nullable: true }) estimatedValue: number | null;
  @Column({ type: 'decimal', precision: 15, scale: 2, nullable: true }) reservePrice: number | null;

  @Column({ type: 'date', nullable: true }) auctionDate: string | null;
  @Column({ type: 'varchar', length: 20, nullable: true }) auctionDateBs: string | null;
  @Column({ type: 'text', nullable: true }) venue: string | null;
  @Column({ type: 'text', nullable: true }) publicationDetails: string | null;

  @Column({ type: 'varchar', length: 20, default: 'scheduled' })
  auctionStatus: 'scheduled' | 'completed' | 'cancelled' | 'no_bidder' | 'postponed';

  @Column({ type: 'decimal', precision: 15, scale: 2, nullable: true }) finalSalePrice: number | null;
  @Column({ type: 'varchar', length: 200, nullable: true }) buyerName: string | null;
  @Column({ type: 'varchar', length: 20, nullable: true }) buyerPhone: string | null;
  @Column({ type: 'text', nullable: true }) buyerAddress: string | null;

  @Column({ type: 'text', nullable: true }) remarks: string | null;
  @Column({ type: 'varchar', nullable: true }) officeId: string | null;
  @Column({ type: 'varchar', nullable: true }) createdById: string | null;
  @Column({ type: 'varchar', length: 200, nullable: true }) createdByName: string | null;

  @CreateDateColumn() createdAt: Date;
  @UpdateDateColumn() updatedAt: Date;
  @DeleteDateColumn() deletedAt: Date | null;
}
