"""
FreeExile Storyline & Beggar's Chronicle Data Types and Enums.
Strictly typed dataclasses and domain enums for the narrative progression.
"""

from __future__ import annotations
from enum import Enum
from typing import Dict, List, Optional
from dataclasses import dataclass, field


class StoryAct(Enum):
    ACT_I_HUNGER = "ACT_I_HUNGER"          # Đáy Vực Đói Rét (Lvl 1-10) - Bến Lưu Đày & Bờ Đá
    ACT_II_MIASMA = "ACT_II_MIASMA"        # Vũng Bùn Nhục Nhã (Lvl 10-25) - Đầm Lầy Thối Rữa
    ACT_III_CRUCIBLE = "ACT_III_CRUCIBLE"  # Bão Cát Nung Thể (Lvl 25-45) - Sa Cốt Hoang Mạc
    ACT_IV_TITAN_HUNT = "ACT_IV_TITAN_HUNT"# Trảm Sát Thú Vương (Lvl 45-65) - Phế Tích & Tế Đàn
    ACT_V_SOVEREIGN = "ACT_V_SOVEREIGN"    # Vinh Quang Đỉnh Phong (Lvl 65-100+) - Cõi Hư Không


class BeggarAscentStage(Enum):
    MENDICANT = "MENDICANT"                # Kẻ Ăn Mày Rách Rưới (Khởi đầu tận cùng đói rét)
    SCAVENGER = "SCAVENGER"                # Kẻ Mót Xương Bùn Nhơ (Lội qua đầm lầy, đoạt tàn cốt)
    BONE_WARRIOR = "BONE_WARRIOR"          # Cuồng Cốt Chiến Giả (Róc giáp bọ cạp, lập uy sa mạc)
    PRIMAL_HUNTER = "PRIMAL_HUNTER"        # Thợ Săn Cự Thú Cổ Đại (Trảm thú vương, áo choàng da thú)
    SOVEREIGN_OUTCAST = "SOVEREIGN_OUTCAST"# Bá Chủ Tối Cao Cõi Lưu Đày (Đè bẹp Chúa Tể Hoang Vực)


@dataclass(slots=True, frozen=True)
class JournalEntry:
    journal_id: str
    act: StoryAct
    stage: BeggarAscentStage
    chapter_index: int
    title: str
    narrator_monologue: str
    unlock_quest_id: str
    location_name: str
    quote_highlight: str


@dataclass(slots=True, frozen=True)
class StoryActDefinition:
    act: StoryAct
    title: str
    subtitle: str
    description: str
    recommended_level_range: str
    primary_zone_id: str
    climax_boss_id: str
    climax_boss_name: str
    stage_unlocked: BeggarAscentStage
    completion_reward_title: str
    journal_ids: List[str] = field(default_factory=list)


@dataclass(slots=True, frozen=True)
class StoryCutscene:
    cutscene_id: str
    act: StoryAct
    trigger_quest_id: str
    title: str
    speaker_name: str
    monologue_lines: List[str]
    ambiance_sound: str
    granted_exp: int = 1000


@dataclass(slots=True)
class PlayerStoryState:
    player_id: str
    current_act: StoryAct
    current_stage: BeggarAscentStage
    completed_acts: List[StoryAct]
    unlocked_journal_ids: List[str]
    read_journal_ids: List[str]
    completed_quest_ids: List[str]
    reputation_title: str
    started_at: float
    updated_at: float

    def is_act_completed(self, act: StoryAct) -> bool:
        return act in self.completed_acts

    def is_journal_unlocked(self, journal_id: str) -> bool:
        return journal_id in self.unlocked_journal_ids

    def is_journal_read(self, journal_id: str) -> bool:
        return journal_id in self.read_journal_ids
