from enum import StrEnum
from typing import Annotated

from pydantic import BeforeValidator


class Role(StrEnum):
    SUPPORT = "Support"
    BOT = "Bot"
    MID = "Mid"
    JUNGLE = "Jungle"
    TOP = "Top"


def validate_role(v: str | Role) -> Role:
    """Convert string/int to Role enum"""
    if isinstance(v, Role):
        return v
    if isinstance(v, str):
        # Try by name (case-insensitive)
        try:
            return Role[v.upper()]
        except KeyError:
            # Try by value
            try:
                return Role(int(v))
            except (ValueError, KeyError):
                raise ValueError(f"Invalid role: {v}")
    raise ValueError(f"Invalid role type: {type(v)}")


RoleType = Annotated[Role, BeforeValidator(validate_role)]
