import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  Index,
} from 'typeorm';

@Entity('wallet_transactions')
@Index('idx_wallet', ['wallet_id'])
@Index('idx_credit_type', ['credit_type'])
@Index('idx_type', ['type'])
@Index('idx_reference', ['reference_type', 'reference_id'])
@Index('idx_created', ['created_at'])
export class WalletTransaction {
  @PrimaryGeneratedColumn({ type: 'bigint', unsigned: true })
  id: number;

  @Column({ type: 'bigint', unsigned: true })
  wallet_id: number;

  @Column({ type: 'enum', enum: ['credit', 'debit'] })
  type: 'credit' | 'debit';

  @Column({ type: 'enum', enum: ['job', 'database', 'ai'] })
  credit_type: 'job' | 'database' | 'ai';

  @Column({ type: 'int' })
  amount: number;

  @Column({ length: 100 })
  reason: string;

  @Column({ length: 50, nullable: true })
  reference_type: string;

  @Column({ type: 'int', nullable: true })
  reference_id: number;

  @Column({ type: 'int' })
  balance_after: number;

  @Column({ type: 'datetime', nullable: true })
  expires_at: Date;

  @Column({ default: false })
  is_expired: boolean;

  @CreateDateColumn()
  created_at: Date;
}
