package com.eactive.eai.rms.common.acl.user.mapper;

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.Mapping;
import org.mapstruct.MappingTarget;
import org.mapstruct.NullValuePropertyMappingStrategy;
import org.mapstruct.ReportingPolicy;

import com.eactive.eai.data.entity.onl.unifbwk.UnifBwkTp;
import com.eactive.eai.data.mapper.GenericMapper;
import com.eactive.eai.rms.common.acl.user.ui.UserBizUI;
import com.eactive.eai.rms.data.entity.onl.bzwkdstcd.UserBusiness;

@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface UserBizUIMapper extends GenericMapper<UserBizUI, UserBusiness> {

	@Override
	@Mapping(source = "id.userId", target = "userId")
	@Mapping(source = "id.eaiBzwkDstcd", target = "bizCode")
	UserBizUI toVo(UserBusiness entity);
	
	@Override
	@InheritInverseConfiguration
	UserBusiness toEntity(UserBizUI vo);

	@InheritInverseConfiguration
	@BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
	void updateToEntity(UserBizUI userBizUI, @MappingTarget UserBusiness userBusiness);

	@AfterMapping
	default void setSaveType(UserBizUI userBizUI, @MappingTarget UserBusiness userBusiness) {
		if (StringUtils.isBlank(userBizUI.getSaveType())) {
			userBusiness.setSaveType("R");
		}
	}

	@Mapping(source = "eaibzwkdstcd", target = "bizCode")
	@Mapping(source = "bzwkdsticdesc", target = "bizDesc")
	@Mapping(source = "bzwkdsticname", target = "bizName")
	UserBizUI toVo(UnifBwkTp unifBwkTp);

}
