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

@Entity('game_admins')
@Unique(['license_id', 'steam_id'])
@Check(`"admin_level" IN ('owner', 'admin', 'moderator')`)
export class GameAdmin {
  @PrimaryGeneratedColumn('uuid')
  id: string;

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

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

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

  @Column({ type: 'varchar', length: 20, default: 'admin' })
  admin_level: string;

  @Column({ type: 'jsonb', default: {} })
  permissions: Record<string, any>;

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

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

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

  @ManyToOne(() => User)
  @JoinColumn({ name: 'added_by' })
  adder: User;
}
