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

@Entity('player_sessions')
export class PlayerSession {
  @PrimaryGeneratedColumn('uuid')
  id: string;

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

  @Column({ type: 'varchar', length: 20 })
  steam_id: string;

  @Column({ type: 'varchar', length: 100 })
  player_name: string;

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

  @Column({ type: 'timestamptz', nullable: true })
  session_end: Date | null;

  @Column({ type: 'integer', nullable: true })
  duration_seconds: number | null;

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

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