package com.eactive.eai.custom.adapter.http.util;

import java.util.HashMap;
import java.util.Map;

import com.eactive.eai.util.CryptoUtil;
import com.eactive.eai.util.json.transformer.ValueTransformer;

public class ToCubeOneTransformer implements ValueTransformer<String, String> {
	public static final String AESKEY = "AESKEY";
	public static final String PLAIN_VALUE = "PLAIN_VALUE";
	private final Map<String, Object> properties = new HashMap<>();

	@Override
	public void setProperty(String propertyName, Object value) {
		properties.put(propertyName, value);
	}
	@Override
	public String getProperty(String propertyName) {
		return (String)properties.get(propertyName);
	}
	
	@Override
	public String transform(String value) throws Exception {
		String apiKey = (String) properties.get(ToCubeOneTransformer.AESKEY);
		String text = CryptoUtil.decryptAES(apiKey, value);
		properties.put(PLAIN_VALUE, text);
		return CubeOneCryptoUtil.encryptPI(text);
	}
}