package com.bytesw.bytebot.model.converters;

import com.bytesw.bytebot.model.enums.FrequencyType;

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

@Converter
public class FrequencyTypeConverter implements AttributeConverter<FrequencyType, String> {
    @Override
    public String convertToDatabaseColumn(FrequencyType frequencyType) {
        if (frequencyType == null) return null;
        return frequencyType.getName();
    }

    @Override
    public FrequencyType convertToEntityAttribute(String s) {
        return FrequencyType.fromString(s);
    }
}
