package com.eactive.eai.rms.onl.audit.adapter.map;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

import org.mapstruct.InheritInverseConfiguration;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

import com.eactive.eai.data.entity.onl.adapter.AdapterGroup;
import com.eactive.eai.data.mapper.BaseMapperConfig;
import com.eactive.eai.data.mapper.GenericMapper;
import com.eactive.eai.rms.onl.audit.adapter.ui.AdapterGroupAuditUI;

@Mapper(config = BaseMapperConfig.class, uses = { AdapterAuditUIMapper.class })
public interface AdapterGroupAuditUIMapper extends GenericMapper<AdapterGroupAuditUI, AdapterGroup> {

	@Override
	@Mapping(target = "eailastamndyms", expression = "java(mapLongToString(entity.getEailastamndyms()))")
	AdapterGroupAuditUI toVo(AdapterGroup entity);

	@InheritInverseConfiguration(name = "toVo")
	@Override
	AdapterGroup toEntity(AdapterGroupAuditUI vo);

	default String mapLongToString(LocalDateTime localDateTime) {
		if(localDateTime == null)
			return null;
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
		return localDateTime.format(formatter);
	}
	
}
