'use strict';

const { encrypt, decrypt } = require('../../utils/credentialStore');

function encryptSecret(value) {
  if (!value) return null;
  return encrypt(String(value));
}

function decryptSecret(value) {
  if (!value) return null;
  return decrypt(String(value));
}

function maskSecret(value) {
  if (!value) return '';
  const text = String(value);
  if (text.length <= 8) return '****';
  return `${text.slice(0, 4)}****${text.slice(-4)}`;
}

module.exports = {
  encryptSecret,
  decryptSecret,
  maskSecret,
};
