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

import type { EntityType, VisitorType } from '@core/analytics/domain/entities/PageView';

@Index('IDX_analytics_page_views_entity', ['entityType', 'entityId'])
@Index('IDX_analytics_page_views_session', ['sessionId'])
@Index('IDX_analytics_page_views_timestamp', ['timestamp'])
@Entity({ name: 'analytics_page_views' })
export class PageViewOrmEntity {
  @PrimaryColumn({ type: 'text' })
  id!: string;

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

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

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

  @Column({ type: 'text' })
  visitorType!: VisitorType;

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

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

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

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

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

  @Column({ type: 'int', nullable: true })
  durationMs!: number | null;
}