import { CmUtils } from "../utils/CmUtils";

export function Value(key: string) {
    return function (target, attr: string) {
        Reflect.defineProperty(
            target,
            attr,
            {
                configurable: true,
                enumerable: true,
                get: () => {
                    if (CmUtils.isEmpty(key)) {
                        return undefined
                    } else {
                        const value = process.env[key];
                        if (CmUtils.isNotEmpty(value)) {
                            return value
                        } else if (key.indexOf(":") > -1) {
                            return CmUtils.substringAfterLast(":", key)
                        } else {
                            return value
                        }
                    }
                },
                set: () => { }
            },
        );
    }
}

