package com.eactive.eai.rms.onl.transaction.extnl.mapping;

import com.eactive.eai.data.entity.onl.message.EAIMessageEntity;
import com.eactive.eai.data.mapper.BaseMapperConfig;
import com.eactive.eai.data.mapper.GenericMapper;
import com.eactive.eai.rms.data.entity.onl.code.CodeService;
import com.eactive.eai.rms.onl.manage.serviceinfo.eaimsg.mapping.ServiceMessageUIMapper;
import com.eactive.eai.rms.onl.transaction.extnl.ui.InterfaceUI;
import org.mapstruct.*;
import org.springframework.beans.factory.annotation.Autowired;

@Mapper(config = BaseMapperConfig.class, uses = { ServiceMessageUIMapper.class })
public abstract class InterfaceManUIMapper implements GenericMapper<InterfaceUI, EAIMessageEntity> {

   @Autowired
   private CodeService codeService;

   @Mapping(source = "eaisvcname", target = "eaiSvcName")
   @Mapping(source = "eaibzwkdstcd", target = "eaiBzwkDstcd")
   @Mapping(target = "eaiTranName", expression = "java(entity.getEaisvcname().substring(0, entity.getEaisvcname().length() - 2))")
   @Mapping(source = "eaisvcdesc", target = "eaiSvcDesc")
   @Mapping(target = "splizDmndDstcd", expression = "java(entity.getEaisvcname().substring(entity.getEaisvcname().length()-2, entity.getEaisvcname().length()-1))")
   @Mapping(target = "stndTelgmWtinExtnlDstcd", expression = "java(entity.getEaisvcname().substring(entity.getEaisvcname().length()-1, entity.getEaisvcname().length()))")
   @Mapping(target = "fromName", expression="java(entity.getEaisvcname().substring(0,3))")
   @Mapping(target = "toName", expression="java(entity.getEaisvcname().substring(4,7))")

   @Mapping(source = "gstatsysadptrbzwkgroupname", target = "fromAdapter")
   @Mapping(source = "svcmotivusedstcd", target = "svcMotivUseDstcd")

   @Mapping(source = "flowctrlroutname", target = "flowCtrlRoutName")
   @Mapping(source = "dmnderrchngidname", target = "dmndErrChngIdName")
   @Mapping(source = "rspnserrchngidname", target = "rspnsErrChngIdName")
   @Mapping(source = "rspnserrfldname", target = "rspnsErrFldName")
   @Mapping(source = "eaisevrdstcd", target = "eaiSevrDstcd")
   @Mapping(source = "eaigroupcocd", target = "eaiGroupCoCd")
   @Mapping(source = "modfimgtstusdstcd", target = "modfiMgtStusDstcd")
   @Mapping(source = "trantype", target = "tranType")
   @Mapping(source = "useyn", target = "useYn")

//   @Mapping(source = "eailastamndyms", target = "eaiLastAmndYMS")

   @Mapping(source = "svchmseonot", target = "svcHMSEonot")
   @Mapping(source = "svcprcesdsticname", target = "svcPrcesDsticName")
   @Mapping(source = "intgradsticname", target = "intgraDsticName")
   @Mapping(source = "svcbfclmnlogyn", target = "svcBfClmnLogYn")
   @Mapping(source = "gstatsysadptrbzwkgroupname", target = "gstatSysAdptrBzwkGroupName")
   @Mapping(source = "sevrloglvelno", target = "sevrLogLvelNo")
   @Mapping(source = "svcloglvelno", target = "svcLogLvelNo")

   @Mapping(source = "author", target = "author")
   @Mapping(source = "refkey", target = "bzwkSvcKeyName")
   @Mapping(source = "verinfo", target = "verInfo")

   @Override
   public abstract InterfaceUI toVo(EAIMessageEntity entity);

   @InheritInverseConfiguration(name = "toVo")
   @Override
   public abstract EAIMessageEntity toEntity(InterfaceUI vo);

   @InheritConfiguration
   @Mapping(target = "serviceMessages", ignore = true)
   public abstract InterfaceUI toVoWithoutChildren(EAIMessageEntity entity);

   @InheritConfiguration
   @BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
   public abstract void updateEntity(InterfaceUI interfaceUI, @MappingTarget EAIMessageEntity eaiMessageEntity);

}