import pkg from '../../package.json'

export function getCommonStoragePrefix() {
    return `${pkg.name}__${getEnv()}`.toUpperCase()
}

// Generate cache key according to version
export function getStorageShortName() {
    return `${getCommonStoragePrefix()}${`__${pkg.version}`}__`.toUpperCase()
}

export function getAppEnvConfig() {
    const ENV = import.meta.env as unknown as ViteEnv

    const {
        VITE_GLOB_APP_NAME,
        VITE_GLOB_APP_DESCRIPTION,
        VITE_GLOB_API_URL,
        VITE_GLOB_API_URL_PREFIX,
        VITE_GLOB_UPLOAD_URL,
    } = ENV

    return {
        VITE_GLOB_APP_NAME,
        VITE_GLOB_APP_DESCRIPTION,
        VITE_GLOB_API_URL,
        VITE_GLOB_API_URL_PREFIX,
        VITE_GLOB_UPLOAD_URL,
    }
}

/**
 * @description: Development mode
 */
export const devMode = 'development'

/**
 * @description: Production mode
 */
export const prodMode = 'production'

/**
 * @description: Get environment variables
 * @returns:
 * @example:
 */
export function getEnv(): string {
    return import.meta.env.MODE
}

/**
 * 获取运行环境中文标识
 * @returns string
 */
export function getEnvText(): string {
    switch (import.meta.env.MODE) {
        case 'test':
        case 'alpha':
            return '内测版'
        case 'beta':
            return '公测版'
        case 'preview':
            return '预览版'
        case 'production':
            return '正式版'
        case 'development':
        default:
            return '开发版'
    }
}

/**
 * @description: Is it a development mode
 * @returns:
 * @example:
 */
export function isDevMode(): boolean {
    return import.meta.env.DEV
}

/**
 * @description: Is it a production mode
 * @returns:
 * @example:
 */
export function isProdMode(): boolean {
    return import.meta.env.PROD
}
