package com.sshproxy.vpn.data

data class TunnelConfig(
    val host: String = "",
    val port: Int = 22,
    val username: String = "",
    val authMethod: SshAuthMethod = SshAuthMethod.PUBLIC_KEY,
    val privateKeyPath: String = "",
    val keyPassphrase: String = "",
    val password: String = "",
    /** Локальный порт SSH -L (tun2socks подключается сюда). */
    val socksPort: Int = DEFAULT_LOCAL_SOCKS_PORT,
    /** Адрес SOCKS5 с UDP на SSH-сервере (обычно 127.0.0.1). */
    val remoteSocksHost: String = DEFAULT_REMOTE_SOCKS_HOST,
    /** Порт hev-socks5-server на SSH-сервере. */
    val remoteSocksPort: Int = DEFAULT_REMOTE_SOCKS_PORT,
    /** Логин SOCKS5 на сервере (если hev-socks5-server с авторизацией). */
    val remoteSocksUsername: String = "",
    /** Пароль SOCKS5 на сервере. */
    val remoteSocksPassword: String = "",
    val acceptUnknownHostKey: Boolean = true,
    val keepAliveIntervalSec: Int = DEFAULT_KEEP_ALIVE_INTERVAL_SEC,
    val autoReconnect: Boolean = true
) {
    fun isValid(): Boolean =
        host.isNotBlank() &&
            username.isNotBlank() &&
            port in 1..65535 &&
            socksPort in 1..65535 &&
            remoteSocksHost.isNotBlank() &&
            remoteSocksPort in 1..65535 &&
            when (authMethod) {
                SshAuthMethod.PUBLIC_KEY -> privateKeyPath.isNotBlank()
                SshAuthMethod.PASSWORD -> password.isNotBlank()
            }

    companion object {
        const val DEFAULT_LOCAL_SOCKS_PORT = 10808
        const val DEFAULT_REMOTE_SOCKS_HOST = "127.0.0.1"
        const val DEFAULT_REMOTE_SOCKS_PORT = 1080
        const val DEFAULT_KEEP_ALIVE_INTERVAL_SEC = 30
        const val MIN_KEEP_ALIVE_INTERVAL_SEC = 10
        const val MAX_KEEP_ALIVE_INTERVAL_SEC = 300
    }
}
