"""
Module defining structures useful to the core class and related methods
"""
from __future__ import annotations
from dataclasses import dataclass
from typing import (
    Any,
    Callable,
    TYPE_CHECKING,
    Optional,
    TypedDict,
    Concatenate,
    ParamSpec,
    TypeVar,
)

if TYPE_CHECKING:
    from poezio import windows

P = ParamSpec('P')
T = TypeVar('T')

__all__ = [
    'Command',
    'Completion',
    'POSSIBLE_SHOW',
    'Status',
]

POSSIBLE_SHOW = {
    'available': None,
    'chat': 'chat',
    'away': 'away',
    'afk': 'away',
    'dnd': 'dnd',
    'busy': 'dnd',
    'xa': 'xa'
}


@dataclass(slots=True)
class Status:
    show: str
    message: str


class Completion:
    """
    A completion result essentially currying the input completion call.
    """
    __slots__ = ('func', 'args', 'kwargs', 'comp_list')

    def __init__(
        self,
        func: Callable[Concatenate[list[str], P], bool],
        comp_list: list[str],
        *args: P.args,
        **kwargs: P.kwargs,
    ) -> None:
        self.func = func
        self.comp_list = comp_list
        self.args = args
        self.kwargs = kwargs

    def run(self) -> bool:
        return self.func(self.comp_list, *self.args, **self.kwargs)


GenericCompletion = (
    Callable[['windows.Input'], Completion | None]
    | Callable[['windows.Input'],  Completion]
    | None
)


@dataclass(slots=True)
class Command:
    func: Callable[..., Any]
    desc: str
    comp: Optional[Callable[['windows.Input'], Completion | None]]
    short_desc: str
    usage: str


class CommandKwargs(TypedDict, total=False):
    desc: str
    shortdesc: str
    completion: Callable[['windows.Input'], Completion | None] | None
    usage: str
