package eu.dnetlib.goldoa.domain;

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;

/**
 * Created by panagiotis on 23/1/2017.
 */
@Converter(autoApply = true)
public class CurrencyConverter implements AttributeConverter<Currency,String> {

    public String convertToDatabaseColumn(Currency value) {
        if ( value == null ) {
            return null;
        }
        return value.getName();
    }


    public Currency convertToEntityAttribute(String value) {
        if ( value == null ) {
            return null;
        }

        if(Currency.getEnum(value) != null)
            return Currency.getEnum(value);
        return Currency.valueOf(value);
    }
}