"""
Pydantic models for request/response validation.
All API request and response models are defined here.
"""
from pydantic import BaseModel
from typing import Optional


# ============================================================================
# Authentication Models
# ============================================================================

class UserRegister(BaseModel):
    email: str
    password: str


class UserLogin(BaseModel):
    email: str
    password: str


class ChangeEmailRequest(BaseModel):
    current_password: str
    new_email: str


class ChangePasswordRequest(BaseModel):
    current_password: str
    new_password: str



# ============================================================================
# Character Models
# ============================================================================

class CharacterCreate(BaseModel):
    name: str
    strength: int = 0
    agility: int = 0
    endurance: int = 0
    intellect: int = 0
    avatar_data: Optional[str] = None


class CharacterSelect(BaseModel):
    character_id: int


# ============================================================================
# Game Action Models
# ============================================================================

class MoveRequest(BaseModel):
    direction: str


class InteractRequest(BaseModel):
    interactable_id: str
    action_id: str


class UseItemRequest(BaseModel):
    item_id: str


class PickupItemRequest(BaseModel):
    item_id: int  # dropped_item database ID
    quantity: int = 1


# ============================================================================
# Combat Models
# ============================================================================

class InitiateCombatRequest(BaseModel):
    enemy_id: int  # wandering_enemies.id


class CombatActionRequest(BaseModel):
    action: str  # 'attack', 'skill', 'flee', 'use_item'
    item_id: Optional[str] = None  # For use_item action
    skill_id: Optional[str] = None  # For skill action


class PvPCombatInitiateRequest(BaseModel):
    target_player_id: int


class PvPAcknowledgeRequest(BaseModel):
    pass  # No body needed


class PvPCombatActionRequest(BaseModel):
    action: str  # 'attack', 'defend', 'flee', 'use_item'
    item_id: Optional[str] = None  # For use_item action


# ============================================================================
# Equipment Models
# ============================================================================

class EquipItemRequest(BaseModel):
    inventory_id: int


class UnequipItemRequest(BaseModel):
    slot: str


class RepairItemRequest(BaseModel):
    inventory_id: int


# ============================================================================
# Crafting Models
# ============================================================================

class CraftItemRequest(BaseModel):
    item_id: str


class UncraftItemRequest(BaseModel):
    inventory_id: int


# ============================================================================
# Corpse/Loot Models
# ============================================================================

class LootCorpseRequest(BaseModel):
    corpse_id: str  # Format: "npc_{id}" or "player_{id}"
    item_index: Optional[int] = None  # Specific item index to loot, or None for all
