package com.eactive.eai.transformer.layout.mapper;

import org.mapstruct.BeanMapping;
import org.mapstruct.InheritConfiguration;
import org.mapstruct.InheritInverseConfiguration;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
import org.mapstruct.NullValuePropertyMappingStrategy;
import org.mapstruct.ReportingPolicy;

import com.eactive.eai.data.entity.onl.transformer.layout.LayoutTypeEntity;
import com.eactive.eai.data.mapper.GenericMapper;
import com.eactive.eai.transformer.dao.TransformerDaoException;
import com.eactive.eai.transformer.layout.LayoutType;
import com.eactive.eai.transformer.layout.LayoutTypeManager;

@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public abstract class LayoutTypeMapper implements GenericMapper<LayoutType, LayoutTypeEntity> {

	@Mapping(source = "loutptrnname", target = "name")
	@Mapping(source = "loutptrndesc", target = "description")
	@Mapping(source = "msgloutcretnclsname", target = "genClass")
	@Override
	public abstract LayoutType toVo(LayoutTypeEntity entity);

	@InheritInverseConfiguration
	@Override
	public abstract LayoutTypeEntity toEntity(LayoutType vo);

	@BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
	@InheritConfiguration
	public abstract void updateFromVo(LayoutType vo, @MappingTarget LayoutTypeEntity entity);

	public LayoutType toLayoutType(String layoutTypeName) {
		LayoutType layoutType = LayoutTypeManager.getInstance().getLayoutType(layoutTypeName);
		if (layoutType == null) {
			throw new TransformerDaoException("LayoutTypeManager에서 LoutPtrnName을 찾을 수 없습니다. - " + layoutTypeName);
		}
		return layoutType;
	}

	public String toString(LayoutType layoutType) {
		return layoutType.getName();
	}

}
