import { Service } from '@zenview/micro-basic-library';
import { cache } from '@zenview/micro-utils';
import URL from "./url";

const getHeaders = () => {
  return {
    Authorization: cache.getCache('token', 'session')
  }
}


class DesensitizationService {
  desensitization(data) {
    return Service.$http({
      headers: getHeaders(),
      url: URL.desensitization.value.replace('<id>', data.userId),
      method: "post",
      data,
      requestId: URL.desensitization.requestId
    })
  }
  getPwKey(password, RSA) {
    return Service.$http({
      url: URL.getPublicKey.value,
      method: 'post',
      requestId: 'getPublicKey',
    }).then((res) => {
      if (!res.data?.publicKey) return '';
      return RSA.encrypt(password, res.data.publicKey) || '';
    });
  }
}

export default new DesensitizationService();
