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

@Entity('player_actions')
@Check(`"action_type" IN ('kick', 'ban', 'unban', 'warn', 'note')`)
export class PlayerAction {
  @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: 'varchar', length: 20 })
  action_type: string;

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

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

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

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

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

  @ManyToOne(() => User)
  @JoinColumn({ name: 'performed_by' })
  performer: User;
}
