'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var nodejs_path = require('../../nodejs/path.js');
var tencentCloud_cos_link = require('../../tencent-cloud/cos/link.js');
var rainbowToCos_helper_valueType = require('./value-type.js');
var string_string = require('../../string/string.js');
var fs_fsUtil = require('../../fs/fs-util.js');
require('@babel/runtime/helpers/toConsumableArray');
require('../../fs/fs.js');
require('../../nodejs/crypto.js');
require('../../nodejs/fs.js');
require('../../nodejs/os.js');
require('../../time/time.js');

function getSaveFileName(_ref) {
  var appName = _ref.appName,
    groupName = _ref.groupName,
    envName = _ref.envName,
    key = _ref.key,
    valueType = _ref.valueType;
  var _a;
  var ext = ((_a = rainbowToCos_helper_valueType.RAINBOW_VALUE_TYPE_MAP[valueType]) === null || _a === void 0 ? void 0 : _a.ext) || 'txt';
  return "".concat(string_string.hyphenate(appName), "__").concat(string_string.hyphenate(groupName), "__").concat(string_string.hyphenate(envName), "__").concat(key, ".").concat(ext);
}
function getSavePath(_ref2) {
  var appName = _ref2.appName,
    groupName = _ref2.groupName,
    envName = _ref2.envName,
    key = _ref2.key,
    valueType = _ref2.valueType;
  return nodejs_path.getPath().resolve(fs_fsUtil.getJsonLogDir(), getSaveFileName({
    appName: appName,
    groupName: groupName,
    envName: envName,
    key: key,
    valueType: valueType
  }));
}
function getCOSFilePath(_ref3) {
  var appName = _ref3.appName,
    groupName = _ref3.groupName,
    envName = _ref3.envName,
    key = _ref3.key,
    valueType = _ref3.valueType,
    cosInfo = _ref3.cosInfo;
  var saveFileName = getSaveFileName({
    appName: appName,
    groupName: groupName,
    envName: envName,
    key: key,
    valueType: valueType
  });
  var bucket = cosInfo.bucket,
    region = cosInfo.region,
    dir = cosInfo.dir;
  return tencentCloud_cos_link.getCosUrlLink({
    bucket: bucket,
    region: region,
    dir: dir,
    fileName: saveFileName
  });
}
var readCOSConfig = function readCOSConfig(saveFileName) {
  var content = [];
  try {
    content = JSON.parse(fs_fsUtil.readJsonLog(saveFileName, '[]'));
  } catch (err) {
    console.log('[readCOSConfig] err: \n', err);
  }
  return content;
};

exports.getCOSFilePath = getCOSFilePath;
exports.getSaveFileName = getSaveFileName;
exports.getSavePath = getSavePath;
exports.readCOSConfig = readCOSConfig;
