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

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.mapstruct.InheritConfiguration;
import org.mapstruct.InheritInverseConfiguration;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;

import com.eactive.eai.data.entity.onl.adapter.Adapter;
import com.eactive.eai.data.mapper.BaseMapperConfig;
import com.eactive.eai.data.mapper.GenericMapper;
import com.eactive.eai.rms.onl.manage.adapter.adapter.ui.AdapterUI;

@Mapper(config = BaseMapperConfig.class, uses = { AdapterPropGroupUIMapper.class })
public interface AdapterUIMapper extends GenericMapper<AdapterUI, Adapter> {

	@Mapping(source = "id.adptrbzwkgroupname", target = "adptrbzwkgroupname")
	@Mapping(source = "id.adptrbzwkname", target = "adptrbzwkname")
	@Override
	AdapterUI toVo(Adapter entity);

	@InheritInverseConfiguration
	@Override
	Adapter toEntity(AdapterUI vo);

	@InheritConfiguration
	void updateToEntity(AdapterUI vo, @MappingTarget Adapter entity);

	default List<Adapter> adapterDataMapToAdapters(Map<String, AdapterUI> adapterData) {
		return adapterData.values().stream().map(this::toEntity).collect(Collectors.toList());
	}

	default Map<String, AdapterUI> adaptersToAdapterDataMap(List<Adapter> adapters) {
		return adapters.stream().map(this::toVo)
				.collect(Collectors.toMap(AdapterUI::getAdptrbzwkname, adapterUI -> adapterUI));
	}

}
