package com.kotcrab.nyx

import java.io.File

/** @author Kotcrab */
object Nyx {
    val NYX_HOME = "NYX_HOME"
    val NYX_HOME_DEFINED = System.getenv(NYX_HOME) != null

    val DEFAULT_CONTEXT = GlobalNyxContext()
}

class GlobalNyxContext : NyxContext {
    override val homeDir by lazy {
        File(System.getenv(Nyx.NYX_HOME) ?: throw IllegalStateException("${Nyx.NYX_HOME} is not defined in system environment variables."))
    }
    override val repositoryDir by lazy {
        homeDir.child("repository")
    }
}

interface NyxContext {
    val homeDir: File
    val repositoryDir: File

    fun getAppDir(name: String): File {
        return repositoryDir.child(name)
    }

    fun scriptExists(scriptName: String): Boolean {
        return homeDir.child(scriptName).exists()
    }

    fun deleteScript(scriptName: String) {
        homeDir.child(scriptName).delete()
    }
}
