from concurrent.futures.thread import ThreadPoolExecutor
from pathlib import Path
from typing import Union

from clarabot_nano.server.base.handler.base import ServerHandleHelper
from clarabot_nano.server.base.handler.filesystem.base import AbstractFileSystemHandler
from clarabot_nano.server.fstx.filesystem.tx_queue import FilesystemTxQueue
from clarabot_nano.server.fstx.tmpfiledb import TemporaryFileDatabase
from clarabot_nano.utility.path.security import set_remote_file_security


class FilesystemTransactorServerHandleHelper(ServerHandleHelper):
    def __init__(self, pool: ThreadPoolExecutor, temp_file_db: TemporaryFileDatabase, fstx_queue: FilesystemTxQueue):
        ServerHandleHelper.__init__(self, pool)
        self.temp_file_db = temp_file_db
        self.fstx_queue = fstx_queue


class AbstractFilesystemTransactorNanoHandler(AbstractFileSystemHandler):
    # fix type hinting
    helper: FilesystemTransactorServerHandleHelper

    def _set_remote_file_security(self, path: Union[str, Path]):
        if self.extracted_config.remote_files_restriction:
            set_remote_file_security(path)
