/**
 * 
 */
package de.bstly.board.model.support;

import java.time.Instant;

import org.hibernate.search.mapper.pojo.bridge.ValueBridge;
import org.hibernate.search.mapper.pojo.bridge.runtime.ValueBridgeFromIndexedValueContext;
import org.hibernate.search.mapper.pojo.bridge.runtime.ValueBridgeToIndexedValueContext;

/**
 * The Class InstantValueBridge.
 */
public class InstantValueBridge implements ValueBridge<Instant, String> {

	/*
	 * @see org.hibernate.search.mapper.pojo.bridge.ValueBridge#toIndexedValue(java.lang.Object, org.hibernate.search.mapper.pojo.bridge.runtime.ValueBridgeToIndexedValueContext)
	 */
	@Override
	public String toIndexedValue(Instant value, ValueBridgeToIndexedValueContext context) {
		return value.toString();
	}

	/*
	 * @see org.hibernate.search.mapper.pojo.bridge.ValueBridge#fromIndexedValue(java.lang.Object, org.hibernate.search.mapper.pojo.bridge.runtime.ValueBridgeFromIndexedValueContext)
	 */
	@Override
	public Instant fromIndexedValue(String value, ValueBridgeFromIndexedValueContext context) {
		return value == null ? null : Instant.parse(value);
	}

}
