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

@Entity({ name: 'stripe_events', schema: 'billing' })
export class StripeEvent {
  @PrimaryGeneratedColumn('uuid')
  id!: string;

  @Column({ name: 'stripe_event_id', type: 'varchar', length: 255, unique: true })
  @Index()
  stripeEventId!: string;

  @Column({ name: 'event_type', type: 'varchar', length: 100 })
  @Index()
  eventType!: string;

  @Column({ name: 'api_version', type: 'varchar', length: 20, nullable: true })
  apiVersion?: string;

  @Column({ type: 'jsonb' })
  data!: Record<string, any>;

  @Column({ type: 'boolean', default: false })
  @Index()
  processed!: boolean;

  @Column({ name: 'processed_at', type: 'timestamptz', nullable: true })
  processedAt?: Date;

  @Column({ name: 'error_message', type: 'text', nullable: true })
  errorMessage?: string;

  @Column({ name: 'retry_count', type: 'integer', default: 0 })
  retryCount!: number;

  @CreateDateColumn({ name: 'created_at', type: 'timestamptz' })
  createdAt!: Date;
}
