from clarabot_nano.common.request.gateway import NanoMutationIdCreateRequest, NanoCreateRoomConfigBlockRequest
from clarabot_nano.common.request.server_fstx import (
    NanoFilesystemDeleteRequest,
    NanoFilesystemMkdirRequest,
    NanoFilesystemPutRequest,
    NanoFilesystemMoveRequest,
    AdminMkdirRequest,
)
from clarabot_nano.common.request.server_general import (
    NanoFilesystemGetRequest,
    NanoFilesystemPeekRequest,
    NanoSearchRequest,
    AdminGetInfoRequest,
    AdminGetRemoteConfigRequest,
    AdminGetListingRequest,
)
from clarabot_nano.common.spawn.constants import ShortNames

# These do not require mutation-session tokens.
IDEMPOTENT_HANDLER_KEYS = set(
    request_cls.TYPE_KEY
    for request_cls in (
        NanoMutationIdCreateRequest,  # permanent lockout otherwise...
        NanoFilesystemGetRequest,
        NanoFilesystemPeekRequest,
        NanoSearchRequest,
        AdminGetInfoRequest,
        AdminGetRemoteConfigRequest,
        AdminGetListingRequest,
    )
)

HANDLER_KEY_PREFIX_MAP = {}
for fstx_request_cls in (
    AdminMkdirRequest,
    NanoFilesystemDeleteRequest,
    NanoFilesystemMkdirRequest,
    NanoFilesystemMoveRequest,
    NanoFilesystemPutRequest,
):
    HANDLER_KEY_PREFIX_MAP[fstx_request_cls.TYPE_KEY] = ShortNames.FSTX_SERVER
for gate_request_cls in (NanoMutationIdCreateRequest, NanoCreateRoomConfigBlockRequest):
    HANDLER_KEY_PREFIX_MAP[gate_request_cls.TYPE_KEY] = ShortNames.GATEWAY


def get_server_prefix_from_request_type(req_type: str) -> str:
    return HANDLER_KEY_PREFIX_MAP.get(req_type, ShortNames.GENERAL_SERVER)
