import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn } from 'typeorm';
import { License } from './license.entity';
import { WebstoreItem } from './webstore-item.entity';

@Entity('webstore_transactions')
export class WebstoreTransaction {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column({ type: 'uuid' })
  license_id: string;

  @Column({ type: 'uuid' })
  item_id: string;

  @Column({ type: 'varchar' })
  buyer_steam_id: string;

  @Column({ type: 'varchar', nullable: true })
  buyer_name: string | null;

  @Column({ type: 'decimal', precision: 10, scale: 2 })
  amount: number;

  @Column({ type: 'varchar', default: 'USD' })
  currency: string;

  @Column({ type: 'varchar', nullable: true })
  paypal_transaction_id: string | null;

  @Column({ type: 'varchar', default: 'pending' })
  status: string;

  @Column({ type: 'timestamptz', nullable: true })
  delivered_at: Date | null;

  @Column({ type: 'timestamptz', default: () => 'NOW()' })
  created_at: Date;

  @ManyToOne(() => License, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'license_id' })
  license: License;

  @ManyToOne(() => WebstoreItem, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'item_id' })
  item: WebstoreItem;
}
