package com.tanpu.community.util;

import com.tanpu.community.api.beans.ThemeDTO;
import com.tanpu.community.api.beans.TopicDTO;
import com.tanpu.community.dao.entity.community.ThemeEntity;
import com.tanpu.community.dao.entity.community.TopicEntity;
import org.springframework.beans.BeanUtils;

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

public class ConvertUtil {

    public static ThemeDTO themeEntityToDTO(ThemeEntity themeEntity){
        ThemeDTO themeDTO = new ThemeDTO();
        BeanUtils.copyProperties(themeEntity, themeDTO);
        return themeDTO;
    }


    public static ThemeEntity themeDTOToEntity(ThemeDTO themeDTO){
        ThemeEntity themeEntity = new ThemeEntity();
        BeanUtils.copyProperties(themeDTO,themeEntity);
        return themeEntity;
    }

    public static List<ThemeDTO> themeEntitiesToDTOs(List<ThemeEntity> themeEntities){
        return themeEntities.stream().map(ConvertUtil::themeEntityToDTO).collect(Collectors.toList());
    }


    public static List<ThemeEntity> themeDTOSToEntitys(List<ThemeDTO> themeDTOS){
        return themeDTOS.stream().map(ConvertUtil::themeDTOToEntity).collect(Collectors.toList());
    }


    public static TopicDTO topicEntityToDTO(TopicEntity topicEntity){
        TopicDTO topicDTO = new TopicDTO();
        BeanUtils.copyProperties(topicEntity,topicDTO);
        return topicDTO;
    }

    public static List<TopicDTO> topicEntitiesToDTOs(List<TopicEntity> topicEntities){
        return topicEntities.stream().map(ConvertUtil::topicEntityToDTO).collect(Collectors.toList());
    }
}