package com.eactive.eai.rms.onl.apim.template;

import org.apache.commons.lang3.StringUtils;
import org.mapstruct.AfterMapping;
import org.mapstruct.BeanMapping;
import org.mapstruct.InheritInverseConfiguration;
import org.mapstruct.Mapper;
import org.mapstruct.MappingTarget;
import org.mapstruct.NullValuePropertyMappingStrategy;
import org.mapstruct.ReportingPolicy;

import com.eactive.apim.portal.template.entity.MessageTemplate;
import com.eactive.eai.data.mapper.GenericMapper;

@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface MessageTemplateUIMapper extends GenericMapper<MessageTemplateUI, MessageTemplate> {

	@Override
	MessageTemplateUI toVo(MessageTemplate entity);

	@Override
	@InheritInverseConfiguration
	MessageTemplate toEntity(MessageTemplateUI vo);

	@InheritInverseConfiguration
	@BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
	void updateToEntity(MessageTemplateUI messageTemplateUI, @MappingTarget MessageTemplate messageTemplate);
	
	@AfterMapping
	default void setEnableN(MessageTemplateUI messageTemplateUI, @MappingTarget MessageTemplate messageTemplate) {
		if(StringUtils.isBlank(messageTemplateUI.getEnableEmail())) {
			messageTemplate.setEnableEmail("N");
		}
		if(StringUtils.isBlank(messageTemplateUI.getEnableMessenger())) {
			messageTemplate.setEnableMessenger("N");
		}
		if(StringUtils.isBlank(messageTemplateUI.getEnableSms())) {
			messageTemplate.setEnableSms("N");
		}
	}
	

}
