import os
from pathlib import Path

VESSL_LOG_LEVEL_DEBUG = "DEBUG"
VESSL_LOG_LEVEL_INFO = "INFO"
VESSL_LOG_LEVEL_WARNING = "WARNING"
VESSL_LOG_LEVEL_ERROR = "ERROR"
VESSL_LOG_LEVEL_LEVELS = [
    VESSL_LOG_LEVEL_DEBUG,
    VESSL_LOG_LEVEL_INFO,
    VESSL_LOG_LEVEL_WARNING,
    VESSL_LOG_LEVEL_ERROR,
]

VESSL_LOG_LEVEL = (
    os.environ.get("VESSL_LOG")
    if os.environ.get("VESSL_LOG") in VESSL_LOG_LEVEL_LEVELS
    else VESSL_LOG_LEVEL_WARNING
)
WEB_HOST = os.environ.get("VESSL_WEB_HOST", "https://vessl.ai")
API_HOST = os.environ.get("VESSL_API_HOST", "https://api.vessl.ai")

LOGIN_TIMEOUT_SECONDS = 160
ACCESS_TOKEN_ENV_VAR = "VESSL_ACCESS_TOKEN"
DEFAULT_ORGANIZATION_ENV_VAR = "VESSL_DEFAULT_ORGANIZATION"
CREDENTIALS_FILE_ENV_VAR = "VESSL_CREDENTIALS_FILE"

PROJECT_TYPE_VERSION_CONTROL = "version-control"
PROJECT_TYPE_CLI_DRIVEN = "cli-driven"
PROJECT_TYPES = [PROJECT_TYPE_VERSION_CONTROL, PROJECT_TYPE_CLI_DRIVEN]

DATASET_PATH_SCHEME_S3 = "s3://"
DATASET_PATH_SCHEME_GS = "gs://"

DATASET_VERSION_HASH_LATEST = "latest"

PROCESSOR_TYPE_CPU = "CPU"
PROCESSOR_TYPE_GPU = "GPU"
PROCESSOR_TYPES = [PROCESSOR_TYPE_CPU, PROCESSOR_TYPE_GPU]

SWEEP_OBJECTIVE_TYPE_MAXIMIZE = "maximize"
SWEEP_OBJECTIVE_TYPE_MINIMIZE = "minimize"
SWEEP_OBJECTIVE_TYPES = [SWEEP_OBJECTIVE_TYPE_MAXIMIZE, SWEEP_OBJECTIVE_TYPE_MINIMIZE]

SWEEP_ALGORITHM_TYPE_GRID = "grid"
SWEEP_ALGORITHM_TYPE_RANDOM = "random"
SWEEP_ALGORITHM_TYPE_BAYESIAN = "baysian"
SWEEP_ALGORITHM_TYPES = [
    SWEEP_ALGORITHM_TYPE_GRID,
    SWEEP_ALGORITHM_TYPE_RANDOM,
    SWEEP_ALGORITHM_TYPE_BAYESIAN,
]

SWEEP_PARAMETER_TYPE_CATEGORICAL = "categorical"
SWEEP_PARAMETER_TYPE_INT = "int"
SWEEP_PARAMETER_TYPE_DOUBLE = "double"
SWEEP_PARAMETER_TYPES = [
    SWEEP_PARAMETER_TYPE_CATEGORICAL,
    SWEEP_PARAMETER_TYPE_INT,
    SWEEP_PARAMETER_TYPE_DOUBLE,
]

SWEEP_PARAMETER_RANGE_TYPE_SPACE = "space"
SWEEP_PARAMETER_RANGE_TYPE_LIST = "list"
SWEEP_PARAMETER_RANGE_TYPES = [
    SWEEP_PARAMETER_RANGE_TYPE_SPACE,
    SWEEP_PARAMETER_RANGE_TYPE_LIST,
]

MOUNT_TYPE_DATASET = "dataset"
MOUNT_TYPE_DATASET_VERSION = "dataset-version"
MOUNT_TYPE_EMPTY_DIR = "empty-dir"
MOUNT_TYPE_OUTPUT = "output"
MOUNT_TYPE_PROJECT = "project"

MOUNT_PATH_EMPTY_DIR = "/work/"
MOUNT_PATH_OUTPUT = "/output/"
MOUNT_PATH_PROJECT = "/work/{}"

PARALLEL_WORKERS = os.environ.get("VESSL_PARALLEL_WORKERS", 20)

VESSL_IMAGE_PATH = "vessl-images"
VESSL_PLOTS_FILETYPE_IMAGE = "image"
VESSL_PLOTS_FILETYPE_IMAGES = "images"

WORKSPACE_ZIP_PATH = "workspace-backup.zip"
WORKSPACE_TEMP_ZIP_PATH = f"/tmp/{WORKSPACE_ZIP_PATH}"

SSH_CONFIG_PATH = f"{Path.home()}/.ssh/config"
SSH_CONFIG_FORMAT = """Host {host}
    User vessl
    Hostname {hostname}
    Port {port}
    StrictHostKeyChecking accept-new
    CheckHostIP no
"""
SSH_PUBLIC_KEY_PATH = f"{Path.home()}/.ssh/id_ed25519.pub"
SSH_PRIVATE_KEY_PATH = f"{Path.home()}/.ssh/id_ed25519"
