from parallels.core import is_run_on_windows
from parallels.plesk.source.web.config import TransferFilesModeOption
from parallels.plesk.source.web.utils.copy_content.linux.ftp import CopyContentLinuxFTP
from parallels.plesk.source.web.utils.copy_content.linux.rsync import CopyContentLinuxRsync
from parallels.plesk.source.web.utils.copy_content.linux.scp import CopyContentLinuxScp
from parallels.plesk.source.web.utils.copy_content.linux.web_streaming import CopyContentLinuxWebStreaming
from parallels.plesk.source.web.utils.copy_content.windows.ftp import CopyContentWindowsFTP
from parallels.plesk.source.web.utils.copy_content.windows.web_streaming import CopyContentWindowsWebStreaming


def create_copy_content(source):
    """
    :type source: parallels.plesk.source.web.connections.WebSource
    :rtype: parallels.plesk.source.web.utils.copy_content.base.CopyContentBase
    """
    if source.config.transfer_files_mode == TransferFilesModeOption.FTP:
        if is_run_on_windows():
            return CopyContentWindowsFTP()
        else:
            return CopyContentLinuxFTP()
    elif source.config.transfer_files_mode == TransferFilesModeOption.SSH_RSYNC:
        return CopyContentLinuxRsync()
    elif source.config.transfer_files_mode == TransferFilesModeOption.SSH_SCP:
        return CopyContentLinuxScp()
    elif source.config.transfer_files_mode == TransferFilesModeOption.WEB_STREAMING:
        if is_run_on_windows():
            return CopyContentWindowsWebStreaming()
        else:
            return CopyContentLinuxWebStreaming()
    else:
        if source.is_ssh_available():
            if source.is_rsync_available():
                return CopyContentLinuxRsync()
            else:
                return CopyContentLinuxScp()
        else:
            if source.config.allow_auto_web_streaming:
                if is_run_on_windows():
                    return CopyContentWindowsWebStreaming()
                else:
                    return CopyContentLinuxWebStreaming()
            else:
                if is_run_on_windows():
                    return CopyContentWindowsFTP()
                else:
                    return CopyContentLinuxFTP()
