from typing import Dict, List, Optional

from pydantic import BaseModel


class displayReward(BaseModel):
    type: str
    id: str
    dropType: str


class displayDetailReward(BaseModel):
    occPercent: str
    type: str
    id: str
    dropType: str


class UnlockCondition(BaseModel):
    stageId: str
    completeState: str


# 主模型包含一个 unlockCondition 列表
class StageInfo(BaseModel):
    unlockCondition: List[UnlockCondition]


class StageDropInfo(BaseModel):
    firstPassRewards: Optional[str] = None
    firstCompleteRewards: Optional[str] = None
    passRewards: Optional[str] = None
    completeRewards: Optional[str] = None
    displayRewards: Optional[List[displayReward]] = []
    displayDetailRewards: Optional[List[displayDetailReward]] = []


class ExtraCondition(BaseModel):
    index: int
    template: str
    unlockParam: List[str]


# 定义奖励结构
class Reward(BaseModel):
    id: str
    count: int
    type: str


# 定义 progressInfo
class ProgressInfo(BaseModel):
    progressType: str
    descList: Optional[Dict[str, str]] = None  # 可能为 null 或为空列表


# 定义 extraInfo 中的每个项
class ExtraInfo(BaseModel):
    stageId: str
    rewards: List[Reward]
    progressInfo: ProgressInfo
    imageId: str


class Stage(BaseModel):
    stageType: str
    difficulty: str
    performanceStageFlag: str
    diffGroup: str
    unlockCondition: List[UnlockCondition]
    stageId: str
    levelId: Optional[str] = None
    zoneId: str
    code: str
    name: Optional[str] = None
    description: Optional[str] = None
    hardStagedId: Optional[str] = None  # 修改为 Optional[str]，允许 None
    dangerLevel: Optional[str] = None
    dangerPoint: float
    loadingPicId: str
    canPractice: bool
    canBattleReplay: bool
    apCost: int
    apFailReturn: int
    etItemId: Optional[str] = None
    etCost: int
    etFailReturn: int
    etButtonStyle: Optional[str] = None
    apProtectTimes: int
    diamondOnceDrop: int
    practiceTicketCost: int
    dailyStageDifficulty: Optional[int] = None
    expGain: int
    goldGain: int
    loseExpGain: int
    loseGoldGain: int
    passFavor: int
    completeFavor: int
    slProgress: int
    displayMainItem: Optional[str] = None
    hilightMark: bool  # 修改为 bool
    bossMark: bool  # 修改为 bool
    isPredefined: bool
    isHardPredefined: bool
    isSkillSelectablePredefined: bool
    isStoryOnly: bool
    appearanceStyle: str
    stageDropInfo: Optional[StageDropInfo] = None  # 修改为模型类型
    canUseCharm: bool
    canUseTech: bool
    canUseTrapTool: bool
    canUseBattlePerformance: bool
    canUseFirework: bool
    canContinuousBattle: bool
    startButtonOverrideId: Optional[str] = None
    isStagePatch: bool
    mainStageId: Optional[str] = None
    extraCondition: Optional[List[ExtraCondition]] = []
    extraInfo: Optional[List[ExtraInfo]] = []


class stageValidInfo(BaseModel):
    startTs: int
    endTs: int


class Stages(BaseModel):
    stages: Dict[str, Stage]
    stageValidInfo: Dict[str, stageValidInfo]
