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

import type { SnapshotEntityType, SnapshotPeriod } from '@core/analytics/domain/entities/AnalyticsSnapshot';
import type { AnalyticsMetrics } from '@core/analytics/domain/types/AnalyticsSnapshot';

@Index('IDX_analytics_snapshots_entity', ['entityType', 'entityId', 'period'])
@Index('IDX_analytics_snapshots_date_range', ['startDate', 'endDate'])
@Entity({ name: 'analytics_snapshots' })
export class AnalyticsSnapshotOrmEntity {
  @PrimaryColumn({ type: 'text' })
  id!: string;

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

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

  @Column({ type: 'text' })
  period!: SnapshotPeriod;

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

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

  @Column({ type: 'jsonb' })
  metrics!: AnalyticsMetrics;

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