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

@Entity('player_quests')
@Index(['characterId', 'questId'], { unique: true })
export class PlayerQuest {
  @PrimaryGeneratedColumn('uuid')
  id: string;

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

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

  @Column({ name: 'quest_id' })
  @Index()
  questId: string;

  @ManyToOne(() => Quest, { eager: true })
  @JoinColumn({ name: 'quest_id' })
  quest: Quest;

  @Column({ default: 0 })
  progress: number;

  @Column({ length: 20, default: 'active' })
  status: string; // 'active' | 'completed' | 'claimed'

  @CreateDateColumn({ name: 'accepted_at' })
  acceptedAt: Date;

  @Column({ name: 'completed_at', type: 'timestamp', nullable: true })
  completedAt: Date | null;
}
