import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn } from 'typeorm';
import { License } from './license.entity';
import { MapLibrary } from './map-library.entity';

@Entity('server_stats')
export class ServerStats {
  @PrimaryGeneratedColumn('uuid')
  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 })
  entity_count: number;

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

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

  @Column({ type: 'uuid', nullable: true })
  map_id: string | null;

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

  @ManyToOne(() => License, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'license_id' })
  license: License;

  @ManyToOne(() => MapLibrary, { onDelete: 'SET NULL', nullable: true })
  @JoinColumn({ name: 'map_id' })
  map: MapLibrary | null;
}
