package com.sshproxy.vpn.service

import android.os.Parcelable
import com.sshproxy.vpn.data.SshAuthMethod
import com.sshproxy.vpn.data.TunnelConfig
import kotlinx.parcelize.Parcelize

@Parcelize
data class TunnelConfigParcelable(
    val host: String,
    val port: Int,
    val username: String,
    val authMethod: SshAuthMethod,
    val privateKeyPath: String,
    val keyPassphrase: String,
    val password: String,
    val socksPort: Int,
    val remoteSocksHost: String,
    val remoteSocksPort: Int,
    val remoteSocksUsername: String,
    val remoteSocksPassword: String,
    val acceptUnknownHostKey: Boolean,
    val keepAliveIntervalSec: Int,
    val autoReconnect: Boolean
) : Parcelable {

    fun toConfig() = TunnelConfig(
        host = host,
        port = port,
        username = username,
        authMethod = authMethod,
        privateKeyPath = privateKeyPath,
        keyPassphrase = keyPassphrase,
        password = password,
        socksPort = socksPort,
        remoteSocksHost = remoteSocksHost,
        remoteSocksPort = remoteSocksPort,
        remoteSocksUsername = remoteSocksUsername,
        remoteSocksPassword = remoteSocksPassword,
        acceptUnknownHostKey = acceptUnknownHostKey,
        keepAliveIntervalSec = keepAliveIntervalSec,
        autoReconnect = autoReconnect
    )

    companion object {
        fun from(config: TunnelConfig) = TunnelConfigParcelable(
            host = config.host,
            port = config.port,
            username = config.username,
            authMethod = config.authMethod,
            privateKeyPath = config.privateKeyPath,
            keyPassphrase = config.keyPassphrase,
            password = config.password,
            socksPort = config.socksPort,
            remoteSocksHost = config.remoteSocksHost,
            remoteSocksPort = config.remoteSocksPort,
            remoteSocksUsername = config.remoteSocksUsername,
            remoteSocksPassword = config.remoteSocksPassword,
            acceptUnknownHostKey = config.acceptUnknownHostKey,
            keepAliveIntervalSec = config.keepAliveIntervalSec,
            autoReconnect = config.autoReconnect
        )
    }
}
