import Sqids from 'sqids';
import crypto from 'crypto-js';
import { CRYPT_API_KEY } from '@/constant/crypt';

const sqidNumber = new Sqids({
  minLength: 36,
});

export const deCryptApiData = (data) => {
  return crypto.AES.decrypt(data, CRYPT_API_KEY).toString(crypto.enc.Utf8);
};

export const enCryptApiData = (data) => {
  return crypto.AES.encrypt(data, CRYPT_API_KEY).toString();
};

/**
 *
 * @param {number} number
 * @returns {string}
 */
export const encryptNumber = (number) => {
  return sqidNumber.encode(number.toString().split(''));
};

/**
 *
 * @param {string} str
 * @returns {number}
 */
export const decryptNumber = (str) => {
  return Number(sqidNumber.decode(str).join(''));
};
