package com.ccnet.acc

import android.content.Context
import com.github.shadowsocks.database.Profile
import timber.log.Timber
import java.io.File

object AccVpn {

    private const val configFilename = "config.conf"

    fun configFile(context: Context): File {
        return File(context.filesDir, configFilename)
    }

    fun writeConfig(context: Context, tunFd: Int, profile: Profile) {
        val configContent = """
            [General]
            loglevel = trace
            dns-server = 8.8.8.8
            tun-fd = $tunFd
            [Proxy]
            Direct = direct
            SS = ss, ${profile.host}, ${profile.remotePort}, encrypt-method=chacha20-ietf-poly1305, password=123456, auth_timeout=${profile.authTimeout}, beats_interval=${profile.beatsInterval}, retry_limit=${profile.retryLimit}, token=${profile.token}
            [Rule]
            FINAL, SS
            """
        val configFile = configFile(context)
        Timber.d("writeConfig ${configFile.absolutePath}")
        configFile.writeText(configContent)
    }
}