import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn } from 'typeorm';
import { GameInstance } from './game-instance.entity';

/**
 * Per-instance time-series game metrics (player count, FPS, …). Populated once
 * game-level telemetry is collected via RCON/plugin — the host heartbeat
 * carries host metrics, not game metrics, so this stays empty in Phase A.
 */
@Entity('instance_stats')
export class InstanceStats {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column({ type: 'uuid' })
  instance_id: string;

  @Column({ type: 'uuid' })
  license_id: string;

  @Column({ type: 'integer', default: 0 })
  player_count: number;

  @Column({ type: 'integer', default: 0 })
  max_players: number;

  @Column({ type: 'double precision', default: 0 })
  fps: number;

  @Column({ type: 'integer', default: 0 })
  memory_usage_mb: number;

  @Column({ type: 'timestamptz', default: () => 'NOW()' })
  recorded_at: Date;

  @ManyToOne(() => GameInstance, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'instance_id' })
  instance: GameInstance;
}
