from mmar_files.config import FilesConfig
from mmar_files.file_storage_api import FileStorageAPI
from mmar_files.file_storage_basic import FileStorageBasic
from mmar_files.file_storage_dir import FileStorageDir
from mmar_files.file_storage_s3 import FileStorageS3


_CONFIG_TO_CLASS_MAP: dict[str, type[FileStorageAPI]] = {
    "basic": FileStorageBasic,
    "dir": FileStorageDir,
    "s3": FileStorageS3,
}


def create_file_storage(files_config: FilesConfig) -> FileStorageAPI:
    storage_type = files_config.type
    storage_handler_factory = _CONFIG_TO_CLASS_MAP.get(storage_type)
    if storage_handler_factory:
        params = files_config.get_config_params()
        return storage_handler_factory(**params)
    return FileStorageBasic()
