package com.eactive.eai.rms.onl.manage.adapter.messagekey;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.mapstruct.Mapper;

import com.eactive.eai.data.entity.onl.messagekey.MessageKey;
import com.eactive.eai.data.entity.onl.messagekey.MessageKeyId;
import com.eactive.eai.data.mapper.BaseMapperConfig;

@Mapper(config = BaseMapperConfig.class)
public interface MessageKeyUIFieldMapper {

	default Map<MessageKeyId, MessageKey> toMessageKeyMap(String adptrBzwkGroupName, String msgDstcd, String ioDstcd,
			Integer groupInorNo, List<MessageKeyUIField> messageKeyUIFields) {
		Map<MessageKeyId, MessageKey> newMessageKeys = new HashMap<>();

		for (MessageKeyUIField messageKeyUIField : messageKeyUIFields) {
			MessageKey messageKey = new MessageKey();
			MessageKeyId messageKeyId = new MessageKeyId();
			messageKeyId.setAdptrbzwkgroupname(adptrBzwkGroupName);
			messageKeyId.setGroupinorno(groupInorNo);
			messageKeyId.setIodstcd(ioDstcd);
			messageKeyId.setMsgdstcd(msgDstcd);

			messageKeyId.setFldprcssno(messageKeyUIField.getFldPrcssNo());

			messageKey.setId(messageKeyId);
			messageKey.setBzwkfldname(messageKeyUIField.getBzwkFldName());
			messageKey.setClsname(messageKeyUIField.getClsName());
			messageKey.setMsgfldlen(messageKeyUIField.getMsgFldLen());
			messageKey.setMsgfldstartsituval(messageKeyUIField.getMsgFldStartSituVal());
			messageKey.setNomalprcssctnt(messageKeyUIField.getNomalPrcssCtnt());

			newMessageKeys.put(messageKeyId, messageKey);
		}
		return newMessageKeys;
	}

}
