import { ConfigRequire } from '../models/ConfigRequire'

export abstract class ConfigLoader {

    /**
     * 环境代码
     */
    meEnv?: string;
    /**
     * 环境秘钥
     */
    meEnvKey?: string;

    /**
     * 配置文件本地保存路径
     * 
     */
    configLocalPath?: string;

    /**
     * 配置中心服务地址
     */
    configServerUrl?: string;

    constructor(meEnv: string, meEnvKey: string, configLocalPath: string
        , configServerUrl: string) {
        this.meEnv = meEnv
        this.meEnvKey = meEnvKey
        this.configLocalPath = configLocalPath
        this.configServerUrl = configServerUrl
    }

    /**
     * 加载配置
     * @param configData 配置内容
     */
    async abstract load(configData: Map<string, any>, configRequires?: Array<ConfigRequire>)


    /**
     * 组装文件保存路径
     * @param configRequire 
     */
    protected assembleFilePath(configRequire: ConfigRequire): string {
        return `${this.configLocalPath}/${configRequire.configCode}-${configRequire.version}-${this.meEnv}`
    }
}