"""
Canonical Data Transfer Objects and Enums for Social & Party E2E Testing.
"""

from __future__ import annotations
import enum
from dataclasses import dataclass, field
from typing import Dict


class LootAllocationMode(enum.Enum):
    PERMANENT = "PERMANENT"
    SHORT = "SHORT"
    FREE_FOR_ALL = "FREE_FOR_ALL"


class TargetType(enum.Enum):
    PARTY_MEMBER = "PARTY_MEMBER"
    FRIEND = "FRIEND"
    GUILDMATE = "GUILDMATE"
    TOWN_PORTAL = "TOWN_PORTAL"


class InterruptReason(enum.Enum):
    INTERRUPT_MOVEMENT = "INTERRUPT_MOVEMENT"
    INTERRUPT_DAMAGE = "INTERRUPT_DAMAGE"


@dataclass(slots=True)
class PartyMemberState:
    player_id: str
    name: str
    level: int
    zone_id: str
    instance_id: str
    x: float
    y: float
    is_alive: bool = True


@dataclass(slots=True)
class PartyState:
    party_id: str
    leader_id: str
    members: Dict[str, PartyMemberState] = field(default_factory=dict)
    loot_allocation_mode: LootAllocationMode = LootAllocationMode.SHORT
    max_members: int = 6


@dataclass(slots=True)
class GroundLootDrop:
    drop_id: str
    item_id: str
    allocated_player_id: str
    drop_timestamp: float
    allocation_mode: LootAllocationMode
    is_picked_up: bool = False

    def can_player_pickup(self, player_id: str, current_time: float) -> bool:
        if self.is_picked_up:
            return False
        if self.allocation_mode == LootAllocationMode.PERMANENT:
            return player_id == self.allocated_player_id
        if self.allocation_mode == LootAllocationMode.SHORT:
            if player_id == self.allocated_player_id:
                return True
            return current_time >= (self.drop_timestamp + 5.0)
        return True  # FREE_FOR_ALL


@dataclass(slots=True)
class FriendPresenceDTO:
    player_id: str
    name: str
    level: int
    is_online: bool
    zone_id: str
    zone_name: str
    note: str = ""


@dataclass(slots=True)
class GuildMemberPresenceDTO:
    player_id: str
    name: str
    level: int
    rank: str
    is_online: bool
    zone_id: str
