<?php
// Copyright 1999-2017. Plesk International GmbH. All rights reserved.

namespace Plesk\MigrationLibV8\SiteImport\Entity;

class SourceServerAccess
{
    /** @var string */
    private $_host;
    /** @var string */
    private $_username;
    /** @var string */
    private $_password;
    /** @var string|null  */
    private $_siteUrl;
    /** @var string|null */
    private $_siteDocumentRoot;
    /** @var string|null */
    private $_ftpEncoding;
    /** @var bool */
    private $_fileTransport;
    /** @var string|null */
    private $_transferFilesMode;
    /** @var bool|null */
    private $_allowAutoWebStreaming;
    /** @var string|null */
    private $_filesRoot;
    /** @var string|null */
    private $_sshPort;
    /** @var bool|null */
    private $_ignorePassiveModeServerIp;
    /** @var string|null */
    private $_listFilesMode;

    /**
     * SourceServerAccess constructor.
     *
     * @param $host string domain name of source server (must be resolvable to the source server)
     * @param $username string FTP/SSH username
     * @param $password string FTP/SSH password
     * @param $siteUrl string|null full URL of the site (use when FTP root or SSH home is in a
     * folder inside document root), e.g. http://example.com/blog/ is a FTP root ("/");
     * in most cases don't specify that parameter
     * @param $siteDocumentRoot string|null document root of the site relative to FTP root (SSH home); in most cases,
     * automatic detection of document root works well, but when it does not (e.g. when there are rewrite rules)
     * then you could specify document root manually.
     * @param $ftpEncoding string|null encoding in which FTP server returns directory listings
     * @param $fileTransport string|null File transport used for deployment of Web RPC agent
     * and file operations on remote server (like upload file, create directory, etc).
     * See constants from \Plesk\MigrationLibV8\SiteImport\Entity\FileTransports.
     * @param $transferFilesMode string|null Way to transfer application files and folders from the source server.
     * See constants from \Plesk\MigrationLibV8\SiteImport\Entity\TransferFileModes.
     * @param $allowAutoWebStreaming bool|null Whether transfer of files with web streaming should
     * be automatically selected when it makes sense. Web streaming makes sense in case
     * when 'transfer-files-mode' is 'auto' and actual file transport is FTP. Web streaming is a beta feature,
     * and so it is not selected by default.
     * @param $filesRoot string|null Path to start scan for files, applications and document root,
     * related to FTP/SSH root. When not specified, default is used: when transport is FTP,
     * then FTP root is used, when transport is SSH, then home directory of SSH user is used.
     * @param $sshPort string|null port to connect to the source website by SSH
     * @param $ignorePassiveModeServerIp bool|null Whether to ignore IP address returned by FTP server
     * when opening data channel in passive mode.
     * When is set to true, IP address returned by FTP server when opening data channel
     * in passive mode is ignored. That option could be necessary because some misconfigured
     * FTP servers return internal IPs, which could not be used to connect to the server.
     * When the option is set, hostname specified for control connection to the FTP server
     * will be used for data connections.
     * @param $listFilesMode string|null Way to list files on the source server
     * Possible ways: with file transport (FTP or SSH - see "file-transport" option), with Web RPC agent,
     * with Web RPC agent with fallback to file transport.
     * General considerations:
     * - Listing with Web RPC agent works much more fast than listing with FTP, but it could be less reliable.
     * - When FTP is used as file transport, listing with Web RPC agent with FTP fallback in
     * case of unicode names and or any failure of RPC agent takes advantages of both ways:
     * usually it works fast, but in case of any failure it works like FTP listing, so it is reliable.
     * By default, migrator automatically selects the way which is optimal for most cases.
     * Possible values: 'auto', 'file-transport', 'web-rpc-agent', 'hybrid'
     */
    public function __construct(
        $host, $username, $password, $siteUrl=null, $siteDocumentRoot=null, $ftpEncoding=null,
        $fileTransport=null, $transferFilesMode=null, $allowAutoWebStreaming=null,
        $filesRoot=null, $sshPort=null, $ignorePassiveModeServerIp=null, $listFilesMode=null
    ) {
        $this->_host = $host;
        $this->_username = $username;
        $this->_password = $password;
        $this->_siteUrl = $siteUrl;
        $this->_siteDocumentRoot = $siteDocumentRoot;
        $this->_ftpEncoding = $ftpEncoding;
        $this->_fileTransport = $fileTransport;
        $this->_transferFilesMode = $transferFilesMode;
        $this->_allowAutoWebStreaming = $allowAutoWebStreaming;
        $this->_filesRoot = $filesRoot;
        $this->_sshPort = $sshPort;
        $this->_ignorePassiveModeServerIp = $ignorePassiveModeServerIp;
        $this->_listFilesMode = $listFilesMode;
    }

    /**
     * Get domain name of source server (must be resolvable to the source server).
     *
     * @return string
     */
    public function getHost()
    {
        return $this->_host;
    }

    /**
     * Get FTP/SSH username.
     *
     * @return string
     */
    public function getUsername()
    {
        return $this->_username;
    }

    /**
     * Get FTP/SSH password.
     *
     * @return string
     */
    public function getPassword()
    {
        return $this->_password;
    }

    /**
     * Get full URL of the site, if it was specified.
     *
     * @return string|null
     */
    public function getSiteUrl()
    {
        return $this->_siteUrl;
    }

    /**
     * Get site document root, if it was specified.
     *
     * @return string|null
     */
    public function getSiteDocumentRoot()
    {
        return $this->_siteDocumentRoot;
    }

    /**
     * Get encoding in which FTP server returns directory listings.
     *
     * @return null|string
     */
    public function getFtpEncoding()
    {
        return $this->_ftpEncoding;
    }

    /**
     * @return null|string
     */
    public function getFileTransport()
    {
        return $this->_fileTransport;
    }

    /**
     * @return null|string
     */
    public function getTransferFilesMode()
    {
        return $this->_transferFilesMode;
    }

    /**
     * @return bool|null
     */
    public function getAllowAutoWebStreaming()
    {
        return $this->_allowAutoWebStreaming;
    }

    /**
     * Get path to start scan for files, applications and document root, related to FTP/SSH root.
     * When not specified, default is used: when transport is FTP,
     * then FTP root is used, when transport is SSH, then home directory of SSH user is used.
     *
     * @return string|null
     */
    public function getFilesRoot()
    {
        return $this->_filesRoot;
    }

    /**
     * Get port to connect to the source website by SSH.
     *
     * @return string|null
     */
    public function getSSHPort()
    {
        return $this->_sshPort;
    }

    /**
     * Whether to ignore IP address returned by FTP server when opening data channel in passive mode.
     *
     * When is set to true, IP address returned by FTP server when opening data channel
     * in passive mode is ignored. That option could be necessary because some misconfigured
     * FTP servers return internal IPs, which could not be used to connect to the server.
     * When the option is set, hostname specified for control connection to the FTP server
     * will be used for data connections.
     *
     * @return bool|null
     */
    public function getIgnorePassiveModeServerIp()
    {
        return $this->_ignorePassiveModeServerIp;
    }

    /**
     * Way to list files on the source server
     *
     * Possible ways: with file transport (FTP or SSH - see "file-transport" option), with Web RPC agent,
     * with Web RPC agent with fallback to file transport.
     *
     * General considerations:
     * - Listing with Web RPC agent works much more fast than listing with FTP, but it could be less reliable.
     * - When FTP is used as file transport, listing with Web RPC agent with FTP fallback in
     * case of unicode names and or any failure of RPC agent takes advantages of both ways:
     * usually it works fast, but in case of any failure it works like FTP listing, so it is reliable.
     * By default, migrator automatically selects the way which is optimal for most cases.
     *
     * Possible values: 'auto', 'file-transport', 'web-rpc-agent', 'hybrid'
     *
     * @return string|null
     */
    public function getListFilesMode()
    {
        return $this->_listFilesMode;
    }
}
