package com.eactive.eai.rms.onl.manage.comm.codeMan;

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.mapper.GenericMapper;
import com.eactive.eai.rms.data.entity.onl.code.Code;
import com.eactive.eai.rms.data.entity.onl.code.CodeId;

@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface CodeMapper extends GenericMapper<CodeUI, Code> {

	@Override
	@Mapping(source = "id.code", target = "code")
	@Mapping(source = "id.codegroup", target = "codeGroup")
	@Mapping(source = "id.codegroup", target = "id")
	@Mapping(source = "parentcode", target = "parentCode")
	@Mapping(source = "codename", target = "codeName")
	@Mapping(source = "useyn", target = "useYn")
	@Mapping(source = "codenameEn", target = "codeName_En")
	CodeUI toVo(Code entity);

	@Override
	@Mapping(source = "code", target = "id.code")
	@Mapping(source = "codeGroup", target = "id.codegroup")
	@InheritInverseConfiguration
	Code toEntity(CodeUI vo);

	@Mapping(source = "codeGroup", target = "codegroup")
	CodeId toId(CodeUI vo);

	@InheritInverseConfiguration
	@BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
	void updateToEntity(CodeUI codeUI, @MappingTarget Code code);

}
