# Released under the MIT License. See LICENSE for details.
#
"""Chest related functionality."""

from dataclasses import dataclass
from typing import TYPE_CHECKING

from bacommon.classic import (
    ClassicChestAppearance,
    CHEST_APPEARANCE_TINTS,
    CHEST_APPEARANCE_TINT_DEFAULT,
)
from bascenev1 import classicassets

if TYPE_CHECKING:
    pass


def _tex(name: str) -> str:
    """Qualified classicassets ref for a chest texture name."""
    return f'{classicassets.__asset_package__}:textures/{name}'


@dataclass
class ChestAppearanceDisplayInfo:
    """Info about how to locally display chest appearances."""

    # NOTE TO SELF: Don't rename these attrs; the C++ layer is hard
    # coded to look for them.

    texclosed: str
    texclosedtint: str
    texopen: str
    texopentint: str
    color: tuple[float, float, float]
    tint: tuple[float, float, float]
    tint2: tuple[float, float, float]


#: Fallback :class:`ChestAppearanceDisplayInfo` used when a chest's
#: declared appearance has no entry in
#: :data:`CHEST_APPEARANCE_DISPLAY_INFOS`.
CHEST_APPEARANCE_DISPLAY_INFO_DEFAULT = ChestAppearanceDisplayInfo(
    texclosed=_tex('chest_icon'),
    texclosedtint=_tex('chest_icon_tint'),
    texopen=_tex('chest_open_icon'),
    texopentint=_tex('chest_open_icon_tint'),
    color=(1, 1, 1),
    tint=CHEST_APPEARANCE_TINT_DEFAULT[0],
    tint2=CHEST_APPEARANCE_TINT_DEFAULT[1],
)

#: Per-:class:`ClassicChestAppearance` rendering info for chests
#: the engine knows how to draw. Entries absent here fall back to
#: :data:`CHEST_APPEARANCE_DISPLAY_INFO_DEFAULT`.
CHEST_APPEARANCE_DISPLAY_INFOS: dict[
    ClassicChestAppearance, ChestAppearanceDisplayInfo
] = {
    ClassicChestAppearance.L2: ChestAppearanceDisplayInfo(
        texclosed=_tex('chest_icon'),
        texclosedtint=_tex('chest_icon_tint'),
        texopen=_tex('chest_open_icon'),
        texopentint=_tex('chest_open_icon_tint'),
        color=(0.8, 1.0, 0.93),
        tint=CHEST_APPEARANCE_TINTS[ClassicChestAppearance.L2][0],
        tint2=CHEST_APPEARANCE_TINTS[ClassicChestAppearance.L2][1],
    ),
    ClassicChestAppearance.L3: ChestAppearanceDisplayInfo(
        texclosed=_tex('chest_icon'),
        texclosedtint=_tex('chest_icon_tint'),
        texopen=_tex('chest_open_icon'),
        texopentint=_tex('chest_open_icon_tint'),
        color=(0.75, 0.9, 1.3),
        tint=CHEST_APPEARANCE_TINTS[ClassicChestAppearance.L3][0],
        tint2=CHEST_APPEARANCE_TINTS[ClassicChestAppearance.L3][1],
    ),
    ClassicChestAppearance.L4: ChestAppearanceDisplayInfo(
        texclosed=_tex('chest_icon'),
        texclosedtint=_tex('chest_icon_tint'),
        texopen=_tex('chest_open_icon'),
        texopentint=_tex('chest_open_icon_tint'),
        color=(0.7, 1.0, 1.4),
        tint=CHEST_APPEARANCE_TINTS[ClassicChestAppearance.L4][0],
        tint2=CHEST_APPEARANCE_TINTS[ClassicChestAppearance.L4][1],
    ),
    ClassicChestAppearance.L5: ChestAppearanceDisplayInfo(
        texclosed=_tex('chest_icon'),
        texclosedtint=_tex('chest_icon_tint'),
        texopen=_tex('chest_open_icon'),
        texopentint=_tex('chest_open_icon_tint'),
        color=(0.75, 0.5, 2.4),
        tint=CHEST_APPEARANCE_TINTS[ClassicChestAppearance.L5][0],
        tint2=CHEST_APPEARANCE_TINTS[ClassicChestAppearance.L5][1],
    ),
    ClassicChestAppearance.L6: ChestAppearanceDisplayInfo(
        texclosed=_tex('chest_icon'),
        texclosedtint=_tex('chest_icon_tint'),
        texopen=_tex('chest_open_icon'),
        texopentint=_tex('chest_open_icon_tint'),
        color=(1.1, 0.8, 0.0),
        tint=CHEST_APPEARANCE_TINTS[ClassicChestAppearance.L6][0],
        tint2=CHEST_APPEARANCE_TINTS[ClassicChestAppearance.L6][1],
    ),
}
