import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn, Unique } from 'typeorm';
import { License } from './license.entity';

@Entity('server_stats_hourly')
@Unique(['license_id', 'hour'])
export class ServerStatsHourly {
  @PrimaryGeneratedColumn('uuid')
  id: string;

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

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

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

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

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

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

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

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

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