import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  ManyToOne,
  JoinColumn,
  CreateDateColumn,
} from 'typeorm';
import { Character } from '../character/entities/character.entity';
import { Monster } from '../monster/monster.entity';

@Entity('combat_logs')
export class CombatLog {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column({ name: 'character_id' })
  characterId: string;

  @ManyToOne(() => Character)
  @JoinColumn({ name: 'character_id' })
  character: Character;

  @Column({ name: 'monster_id' })
  monsterId: string;

  @ManyToOne(() => Monster)
  @JoinColumn({ name: 'monster_id' })
  monster: Monster;

  @Column({ type: 'varchar', length: 10 })
  winner: 'player' | 'monster';

  @Column({ name: 'total_rounds' })
  totalRounds: number;

  // Stocker les rounds en JSON — lecture replay
  @Column({ name: 'rounds_data', type: 'json' })
  roundsData: object;

  @Column({ name: 'xp_earned', default: 0 })
  xpEarned: number;

  @Column({ name: 'gold_earned', default: 0 })
  goldEarned: number;

  @Column({ name: 'level_up', default: false })
  levelUp: boolean;

  @CreateDateColumn({ name: 'created_at' })
  createdAt: Date;
}
