package eu.eudat.models.rda.mapper;

import java.util.Map;

import eu.eudat.models.rda.Cost;

public class CostRDAMapper {
	
	public static Cost toRDA(Map<String, Object> cost) {
		Cost rda = new Cost();
		Map<String, Object> code = new org.json.JSONObject((String) cost.get("code")).toMap();
		rda.setCurrencyCode(Cost.CurrencyCode.fromValue((String) code.get("value")));
		rda.setDescription((String) cost.get("description"));
		if (cost.get("title") == null) {
			throw new IllegalArgumentException("Cost Title is missing");
		}
		rda.setTitle((String) cost.get("title"));
		rda.setValue(((Integer) cost.get("value")).doubleValue());
		return rda;
	}

}
