# -*- coding: utf-8 -*-
# Copyright © tandemdude 2020-present
#
# This file is part of Lightbulb.
#
# Lightbulb is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Lightbulb is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Lightbulb. If not, see <https://www.gnu.org/licenses/>.
from __future__ import annotations

__all__ = ["MessageContext"]

import typing as t

import hikari

from lightbulb import commands
from lightbulb.context import base

if t.TYPE_CHECKING:
    from lightbulb import app as app_


class MessageContext(base.ApplicationContext):
    """
    An implementation of :obj:`~.context.base.Context` for message context menu commands.

    Args:
        app (:obj:`~.app.BotApp`): The ``BotApp`` instance that the context is linked to.
        event (:obj:`~hikari.events.interaction_events.InteractionCreateEvent`): The event to create the context
            from.
        command (:obj:`~.commands.message.MessageCommand`): The command that the context is for.

    Note that the target message that this command was invoked on will **always** be stored
    as the option ``target``.

    Example:

        .. code-block:: python

            @lightbulb.command("id", "Gets the ID of the selected message")
            @lightbulb.implements(lightbulb.MessageCommand)
            async def get_message_id(ctx: lightbulb.MessageContext) -> None:
                await ctx.respond(ctx.options.target.id)

    .. versionadded:: 2.2.0
    """

    __slots__ = ("_options",)

    def __init__(
        self, app: app_.BotApp, event: hikari.InteractionCreateEvent, command: commands.message.MessageCommand
    ) -> None:
        super().__init__(app, event, command)
        assert self.resolved is not None
        assert self.interaction.target_id is not None
        self._options = {"target": self.resolved.messages.get(self.interaction.target_id)}

    @property
    def raw_options(self) -> t.Dict[str, t.Any]:
        return self._options

    @property
    def command(self) -> commands.message.MessageCommand:
        assert isinstance(self._command, commands.message.MessageCommand)
        return self._command

    @property
    def prefix(self) -> str:
        return "\N{THREE BUTTON MOUSE}\N{VARIATION SELECTOR-16}"
