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

@Entity('payments')
@Unique('uq_receipt', ['receipt'])
@Index('idx_user', ['user_id'])
@Index('idx_status', ['status'])
@Index('idx_gateway', ['gateway_order_id'])
export class Payment {
  @PrimaryGeneratedColumn({ type: 'bigint', unsigned: true })
  id: number;

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

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

  @Column({ type: 'decimal', precision: 5, scale: 2, default: 18.0 })
  gst_percentage: number;

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

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

  @Column({ length: 30 })
  gateway: string;

  @Column({ length: 100, nullable: true })
  gateway_order_id: string;

  @Column({ length: 100, nullable: true })
  gateway_payment_id: string;

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

  @Column({
    type: 'enum',
    enum: ['initiated', 'processing', 'success', 'failed', 'refunded'],
  })
  status: 'initiated' | 'processing' | 'success' | 'failed' | 'refunded';

  @Column({ type: 'json', nullable: true })
  raw_request: any;

  @Column({ type: 'json', nullable: true })
  raw_response: any;

  @CreateDateColumn()
  created_at: Date;
}
