import { Column, Entity, Index, PrimaryColumn } from 'typeorm';

import type { EngagementAction, EngagementEntityType } from '@core/analytics/domain/entities/EngagementEvent';

@Index('IDX_analytics_engagement_events_entity', ['entityType', 'entityId'])
@Index('IDX_analytics_engagement_events_action', ['action'])
@Index('IDX_analytics_engagement_events_timestamp', ['timestamp'])
@Entity({ name: 'analytics_engagement_events' })
export class EngagementEventOrmEntity {
  @PrimaryColumn({ type: 'text' })
  id!: string;

  @Column({ type: 'text' })
  action!: EngagementAction;

  @Column({ type: 'text' })
  entityType!: EngagementEntityType;

  @Column({ type: 'text' })
  entityId!: string;

  @Column({ type: 'text', nullable: true })
  actorId!: string | null;

  @Column({ type: 'text' })
  actorType!: 'anonymous' | 'driver' | 'sponsor';

  @Column({ type: 'text' })
  sessionId!: string;

  @Column({ type: 'jsonb', nullable: true })
  metadata!: Record<string, string | number | boolean> | null;

  @Column({ type: 'timestamptz' })
  timestamp!: Date;
}