import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  ManyToOne,
  JoinColumn,
  Index,
} from 'typeorm';
import { QuestArc } from './quest-arc.entity';

@Entity('quests')
export class Quest {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column({ length: 100 })
  name: string;

  @Column('text')
  description: string;

  // Objectif
  @Column({ name: 'objective_type', length: 30 })
  objectiveType: string; // 'kill_monster' | 'kill_any' | 'gather_material' | 'craft_item' | 'forge_item'

  @Column({ name: 'objective_target_id', type: 'varchar', length: 255, nullable: true })
  objectiveTargetId: string | null; // monster ID or material ID (null for kill_any)

  @Column({ name: 'objective_count', default: 1 })
  objectiveCount: number;

  // Récompenses
  @Column({ name: 'reward_xp', default: 0 })
  rewardXp: number;

  @Column({ name: 'reward_gold', default: 0 })
  rewardGold: number;

  @Column({ name: 'reward_title', type: 'varchar', length: 100, nullable: true })
  rewardTitle: string | null;

  // Arc (optionnel)
  @Column({ name: 'arc_id', type: 'varchar', nullable: true })
  @Index()
  arcId: string | null;

  @ManyToOne(() => QuestArc, (a) => a.quests, { nullable: true })
  @JoinColumn({ name: 'arc_id' })
  arc: QuestArc | null;

  @Column({ name: 'arc_order', default: 0 })
  arcOrder: number; // order within the arc

  // Availability
  @Column({ name: 'min_level', default: 1 })
  minLevel: number;

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