const path = require("node:path");
const os = require("node:os");

const root = path.resolve(__dirname, "../..");

const defaultSystemConfig = {
    aliyun_bailian_api_key: "",
    aliyun_bailian_base_url: "https://dashscope.aliyuncs.com/compatible-mode/v1",
    aliyun_oss_access_key_id: "",
    aliyun_oss_access_key_secret: "",
    aliyun_oss_bucket: "",
    aliyun_oss_region: "oss-cn-beijing",
    volcengine_api_key: "",
    volcengine_model: "doubao-seed-2-0-mini-260215",
    runninghub_api_key: "",
    runninghub_workflow_id_1: "2013514129943826433",
    runninghub_workflow_id_2: "2013514129943826433",
    runninghub_tts_webapp_id_v2: "1965614643077070850",
    runninghub_tts_webapp_id_v3: "2028779949334728706",
    runninghub_tts_v2_audio_node: "13",
    runninghub_tts_v2_text_node: "14",
    runninghub_tts_v2_emotion_node: "15",
    cloud_beauty_base_url: "",
    cloud_beauty_api_key: "",
    cloud_beauty_default_mode: "256m",
    cloud_beauty_enabled: "false",
    trial_duration_hours: "168",
    update_url: "",
};

const systemConfigDescriptions = {
    aliyun_bailian_api_key: "阿里云百炼 / DashScope API Key",
    aliyun_bailian_base_url: "阿里云百炼兼容 OpenAI Base URL",
    aliyun_oss_access_key_id: "阿里云 OSS AccessKey ID",
    aliyun_oss_access_key_secret: "阿里云 OSS AccessKey Secret",
    aliyun_oss_bucket: "阿里云 OSS Bucket",
    aliyun_oss_region: "阿里云 OSS Region",
    volcengine_api_key: "火山引擎 API Key",
    volcengine_model: "火山引擎默认模型",
    runninghub_api_key: "RunningHub API Key",
    runninghub_workflow_id_1: "RunningHub 工作流 ID 1",
    runninghub_workflow_id_2: "RunningHub 工作流 ID 2",
    runninghub_tts_webapp_id_v2: "RunningHub TTS WebApp ID V2",
    runninghub_tts_webapp_id_v3: "RunningHub TTS WebApp ID V3",
    runninghub_tts_v2_audio_node: "RunningHub TTS V2 音频节点",
    runninghub_tts_v2_text_node: "RunningHub TTS V2 文本节点",
    runninghub_tts_v2_emotion_node: "RunningHub TTS V2 情绪节点",
    cloud_beauty_base_url: "云端美颜 Base URL",
    cloud_beauty_api_key: "云端美颜 API Key",
    cloud_beauty_default_mode: "云端美颜默认模式",
    cloud_beauty_enabled: "是否启用云端美颜",
    trial_duration_hours: "试用时长（小时）",
    update_url: "软件更新地址",
};

function resolveDataDir() {
    if (process.env.LOCAL_AUTH_DATA_DIR) return path.resolve(process.env.LOCAL_AUTH_DATA_DIR);
    return path.join(process.env.APPDATA || os.homedir() || root, "aIzhinengti-clean-local-auth");
}

module.exports = {
    root,
    host: process.env.LOCAL_AUTH_HOST || "127.0.0.1",
    port: Number(process.env.LOCAL_AUTH_PORT || process.env.PORT || 3302),
    dataDir: resolveDataDir(),
    tokenSecret: process.env.LOCAL_AUTH_SECRET || "local-auth-dev-secret",
    adminPanelDir: process.env.ADMIN_PANEL_DIR || path.join(root, "admin-panel"),
    defaultUser: {
        username: process.env.LOCAL_AUTH_DEFAULT_USERNAME || "本地管理员",
        email: process.env.LOCAL_AUTH_DEFAULT_EMAIL || "13800138000",
        password: process.env.LOCAL_AUTH_DEFAULT_PASSWORD || "123456",
    },
    defaultSystemConfig,
    systemConfigDescriptions,
};
